2021年4月7日星期三

Find matching dates between GridViews A & B and auto-tick checkbox in GridView A if theres is match - VB.Net

I have a Gridview that generates the total dates of selected month and displays them in table format, along with a checkbox column.

Said checkbox, when ticked will upload the date, plus additional data from other fields into SQL database. Un-ticking it will delete the data row from the database.

As it is, the GridView cannot remember which row's checkbox was ticked in the last session if I decide to change month or start a new session.

I don't think I can use SQL query to help with that since the GridView content is generated via code and does not use the database. So I made another GridView, this one collects the relevant dates from SQL that have matching information from the additional fields when they were uploaded to database.

My idea was to have the 1st GridView check the data from 2nd GridView and automatically tick the correct checkboxes when it loads.

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowBtn.Click        Call load_Calander()    End Sub    Sub load_Calander()        '~ code to generate date column in GridView1 ~'        'code that generates GridView2 (SQL data)      Dim cmd As New SqlCommand      Dim DateTB As New DataSet        Dim DateCmd As String = "select ScheduleDate FROM [SQLIOT].[dbo].[ZEPB_PreventiveDateSchedule] " _                              & " where line_desc = '" & LineList.SelectedItem.Text & "' and process = '" & ProcessList.SelectedItem.Text & "' " _                              & " and machine = '" & MachineList.SelectedItem.Text & "' and Step = '" & StepList.SelectedItem.Text & "' " _                              & " and inspection = '" & InspectionList.SelectedItem.Text & "' and  specification = '" & SpecificationList.SelectedItem.Text & "' "        Dim da As New SqlDataAdapter(DateCmd, Conn)        cmd.Connection = Conn        Conn.Open()      da.Fill(DateTB, "TempStore")        Dim dvgroup As DataView = DateTB.Tables("TempStore").DefaultView        GridView2.DataSource = dvgroup      GridView2.DataBind()        Conn.Close()        'code to cross-reference and auto tick checkbox - Currently empty...        

Currently I'm a little stuck on how to code the cross-reference part.

https://stackoverflow.com/questions/66996046/find-matching-dates-between-gridviews-a-b-and-auto-tick-checkbox-in-gridview-a April 08, 2021 at 09:08AM

没有评论:

发表评论