This is my 1st post.I have two checkbox columns in gridview binded through item template. The checkboxes are Category and Subcategory. I have actually removed the duplicate values in the 1st column so that Category is listed only once for the corresponding subcategories. Now I need to make sure that the all the subcategory checkboxes to be checked when the corresponding category checkbox is checked. The issue is that only the first subcategory is checked and the remaining subcategory checkboxes are unchecked as the duplicate category checkboxes are not visible. Can someone please help me out...
Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="GridView1" runat="server" AllowPaging="False" AllowSorting="True"
- HorizontalAlign="Center" AutoGenerateColumns="False" DataSourceID="CatSource"
- Width="496px" CellPadding="4" ForeColor="#333333" GridLines="Vertical">
- <Columns>
- <%-- <asp:BoundField DataField="M_CATPAGES_CAT" />
- <asp:BoundField DataField="M_PAGES_PAGES" />--%>
- <asp:TemplateField>
- <HeaderTemplate>
- <input type="checkbox" id="chkAll" name="chkAll" onclick="check(this)" />
- </HeaderTemplate>
- <ItemTemplate>
- <asp:CheckBox ID="chkSelect" runat="server" Text='<%# Eval("M_CATPAGES_CAT") %>' AutoPostBack ="true" OnCheckedChanged ="subcat_selectedchanged" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField >
- <ItemTemplate>
- <asp:Label ID="lblcatid" runat="server" Text='<%#Eval("M_CATPAGES_ID") %>' Visible="true"></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:CheckBox ID="chkSubcat" runat="server" Text='<%# Eval("M_PAGES_PAGES") %>' />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:Label ID="lblsubcat" runat="server" Text='<%#Eval("M_PAGES_ID_PK") %>' Visible="true"></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField >
- <ItemTemplate >
- <asp:Label ID="lblcatsubcatid" runat="server" Text='<%#Eval("M_PAGES_CATID") %>' Visible="true"></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
Expand|Select|Wrap|Line Numbers
- Protected Sub CheckDuplicateValue()
- Dim cbxCat1 As CheckBox = New CheckBox()
- Dim iValue As String = String.Empty
- For i As Integer = 0 To GridView1.Rows.Count - 1
- cbxCat1 = GridView1.Rows(i).FindControl("chkSelect")
- Dim strgdvVal As String = cbxCat1.Text.ToString()
- If (strgdvVal = iValue.ToString()) Then
- cbxCat1.Visible = False
- Else
- iValue = cbxCat1.Text
- End If
- Next
- End Sub
- Protected Sub subcat_selectedchanged(ByVal sender As Object, ByVal e As EventArgs)
- For i As Integer = 0 To GridView1.Rows.Count - 1
- Dim lablcat As Label = DirectCast(GridView1.Rows(i).FindControl("lblcatid"), Label)
- Dim lablsubcat As Label = DirectCast(GridView1.Rows(i).FindControl("lblcatsubcatid"), Label)
- Dim lablsbcat_catid As Label = DirectCast(GridView1.Rows(i).FindControl("lblcatsubcatid"), Label)
- Dim chkCat As CheckBox = DirectCast(GridView1.Rows(i).FindControl("chkSelect"), CheckBox)
- Dim chkSub As CheckBox = DirectCast(GridView1.Rows(i).FindControl("chkSubcat"), CheckBox)
- If lablcat.Text = lablsbcat_catid.Text Then
- If chkCat.Checked = True Then
- chkSub.Checked = True
- Else
- chkSub.Checked = False
- End If
- End If
- Next
- End Sub