I have 2 GridViews in my Web App.
GridView1 contains the entire date selection for the selected month along with a checkbox column. When ticked the date plus additional info is updated to SQL database. Untick deletes the record.
GridView2 is a hidden GridView which contains data of dates from GridView1 that was previously ticked.
My idea is to have GridView1 compare with GridView2 for their dates and if GridView2 have date that matches the selection in GridView1, it will automatically tick it when GridView1 loads.
What I have tried:
Design for GridView1
<asp:GridView ID="GridView1" runat="server" BackColor="#FFFFCC"
ShowHeaderWhenEmpty="True" Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="UpdateDB_click"
autopostback = "true" Wrap="True" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The GridView2 will be loaded at the same time with GridView1, so they will share the same sub.
Sub load_Calander()
Dim year As Integer = Convert.ToInt32(CurrentYear.Text)
Dim month As Integer = Convert.ToInt32(Mth_Num.Text)
If month = 1 Then
Mth_Txt.Text = "Jan"
ElseIf month = 2 Then
Mth_Txt.Text = "Feb"
ElseIf month = 3 Then
Mth_Txt.Text = "Mar"
ElseIf month = 4 Then
Mth_Txt.Text = "Apr"
ElseIf month = 5 Then
Mth_Txt.Text = "May"
ElseIf month = 6 Then
Mth_Txt.Text = "Jun"
ElseIf month = 7 Then
Mth_Txt.Text = "Jul"
ElseIf month = 8 Then
Mth_Txt.Text = "Aug"
ElseIf month = 9 Then
Mth_Txt.Text = "Sep"
ElseIf month = 10 Then
Mth_Txt.Text = "Oct"
ElseIf month = 11 Then
Mth_Txt.Text = "Nov"
ElseIf month = 12 Then
Mth_Txt.Text = "Dec"
End If
Dim myList As List(Of [myClass]) = New List(Of [myClass])()
If month = 1 OrElse month = 3 OrElse month = 5 OrElse month = 7 OrElse month = 8 OrElse month = 10 OrElse month = 12 Then
For i As Integer = 1 To 31
Dim item As [myClass] = New [myClass]()
item.[Date] = String.Format("{0}/{1}/{2}", i.ToString(), Mth_Txt.Text, CurrentYear.Text)
Dim dateValue As DateTime = New DateTime(Convert.ToInt32(CurrentYear.Text), Convert.ToInt32(Mth_Num.Text), i)
item.[Day] = dateValue.ToString("ddddddddd")
myList.Add(item)
Next
ElseIf month = 4 OrElse month = 6 OrElse month = 9 OrElse month = 11 Then
For i As Integer = 1 To 30
Dim item As [myClass] = New [myClass]()
item.[Date] = String.Format("{0}/{1}/{2}", i.ToString(), Mth_Txt.Text, CurrentYear.Text)
Dim dateValue As DateTime = New DateTime(Convert.ToInt32(CurrentYear.Text), Convert.ToInt32(Mth_Num.Text), i)
item.[Day] = dateValue.ToString("ddddddddd")
myList.Add(item)
Next
ElseIf DateTime.IsLeapYear(year) Then
For i As Integer = 1 To 29
Dim item As [myClass] = New [myClass]()
item.[Date] = String.Format("{0}/{1}/{2}", i.ToString(), Mth_Txt.Text, CurrentYear.Text)
Dim dateValue As DateTime = New DateTime(Convert.ToInt32(CurrentYear.Text), Convert.ToInt32(Mth_Num.Text), i)
item.[Day] = dateValue.ToString("ddddddddd")
myList.Add(item)
Next
Else
For i As Integer = 1 To 28
Dim item As [myClass] = New [myClass]()
item.[Date] = String.Format("{0}/{1}/{2}", i.ToString(), Mth_Txt.Text, CurrentYear.Text)
Dim dateValue As DateTime = New DateTime(Convert.ToInt32(CurrentYear.Text), Convert.ToInt32(Mth_Num.Text), i)
item.[Day] = dateValue.ToString("ddddddddd")
myList.Add(item)
Next
End If
GridView1.DataSource = myList
GridView1.DataBind()
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()
I want to build an IF-ELSE statement but my knowledge is limited:
Dim rowNo As Integer = (CType((TryCast(sender, Control)).NamingContainer, GridViewRow)).RowIndex
Dim CheckBoxChecked As Boolean = CType(sender, CheckBox).Checked
If GridView1.Rows....