By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

Checkbox issue in Gridview

P: 1
Hi
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
  1.  
  2. <asp:GridView ID="GridView1" runat="server" AllowPaging="False" AllowSorting="True"
  3.         HorizontalAlign="Center" AutoGenerateColumns="False" DataSourceID="CatSource"
  4.         Width="496px" CellPadding="4" ForeColor="#333333" GridLines="Vertical">
  5.         <Columns>
  6.         <%--    <asp:BoundField DataField="M_CATPAGES_CAT" />
  7.             <asp:BoundField DataField="M_PAGES_PAGES" />--%>
  8.             <asp:TemplateField>
  9.                 <HeaderTemplate>
  10.                     <input type="checkbox" id="chkAll" name="chkAll" onclick="check(this)" />
  11.                 </HeaderTemplate>
  12.                 <ItemTemplate>
  13.                     <asp:CheckBox ID="chkSelect" runat="server" Text='<%# Eval("M_CATPAGES_CAT") %>' AutoPostBack ="true" OnCheckedChanged ="subcat_selectedchanged"  />
  14.  
  15.                 </ItemTemplate>
  16.             </asp:TemplateField>
  17.             <asp:TemplateField >
  18.                 <ItemTemplate>
  19.                      <asp:Label ID="lblcatid" runat="server" Text='<%#Eval("M_CATPAGES_ID") %>' Visible="true"></asp:Label>
  20.                 </ItemTemplate> 
  21.             </asp:TemplateField>
  22.             <asp:TemplateField>
  23.                 <ItemTemplate>
  24.                     <asp:CheckBox ID="chkSubcat" runat="server" Text='<%# Eval("M_PAGES_PAGES") %>'   />
  25.  
  26.                 </ItemTemplate>
  27.             </asp:TemplateField>
  28.  
  29.               <asp:TemplateField>
  30.                      <ItemTemplate>
  31.                     <asp:Label ID="lblsubcat" runat="server" Text='<%#Eval("M_PAGES_ID_PK") %>' Visible="true"></asp:Label>
  32.  
  33.                     </ItemTemplate>
  34.                 </asp:TemplateField>
  35.                 <asp:TemplateField >
  36.                 <ItemTemplate >
  37.                 <asp:Label ID="lblcatsubcatid" runat="server" Text='<%#Eval("M_PAGES_CATID") %>' Visible="true"></asp:Label>
  38.  
  39.                 </ItemTemplate>
  40.                 </asp:TemplateField>
  41.  
  42.  
  43.         </Columns>
  44.     </asp:GridView>
  45.  
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub CheckDuplicateValue()
  2.         Dim cbxCat1 As CheckBox = New CheckBox()
  3.  
  4.  
  5.  
  6.         Dim iValue As String = String.Empty
  7.         For i As Integer = 0 To GridView1.Rows.Count - 1
  8.             cbxCat1 = GridView1.Rows(i).FindControl("chkSelect")
  9.             Dim strgdvVal As String = cbxCat1.Text.ToString()
  10.             If (strgdvVal = iValue.ToString()) Then
  11.                 cbxCat1.Visible = False
  12.             Else
  13.                 iValue = cbxCat1.Text
  14.             End If
  15.         Next
  16.     End Sub
  17.  
  18.  Protected Sub subcat_selectedchanged(ByVal sender As Object, ByVal e As EventArgs)
  19.         For i As Integer = 0 To GridView1.Rows.Count - 1
  20.             Dim lablcat As Label = DirectCast(GridView1.Rows(i).FindControl("lblcatid"), Label)
  21.             Dim lablsubcat As Label = DirectCast(GridView1.Rows(i).FindControl("lblcatsubcatid"), Label)
  22.             Dim lablsbcat_catid As Label = DirectCast(GridView1.Rows(i).FindControl("lblcatsubcatid"), Label)
  23.             Dim chkCat As CheckBox = DirectCast(GridView1.Rows(i).FindControl("chkSelect"), CheckBox)
  24.             Dim chkSub As CheckBox = DirectCast(GridView1.Rows(i).FindControl("chkSubcat"), CheckBox)
  25.             If lablcat.Text = lablsbcat_catid.Text Then
  26.                 If chkCat.Checked = True Then
  27.                     chkSub.Checked = True
  28.                 Else
  29.                     chkSub.Checked = False
  30.                 End If
  31.             End If
  32.         Next
  33.     End Sub
  34.  
  35.  
Jul 28 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.