473,473 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Checkbox issue in Gridview

1 New Member
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
0 2416

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

Similar topics

1
by: Bill44077 | last post by:
I am dynamically adding a checkbox in a gridview and I find there are several things that I cannot figure out how to address. 1. The width of the checkbox column is very wide. I've tried adding...
0
by: Jayender | last post by:
Hi , I have placed checkbox in my gridview .. now when i check the chekbox and click anybutton the checkbox becomes unchecked. but when i normally add checkbox in the page it doesnt happen but...
1
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in...
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
2
by: JonBosker | last post by:
I am having a strange problem - my GridView is displaying bits (from SQL Server) as checkboxes (which is fine) but it shows each alternating one centrally aligned. Heading1 Heading2 Text ...
3
by: Chris McGrath | last post by:
Hello all, I have a gridview that contains a checkbox for each row and in each row, one of the fields is an asp:HyperLinkField. What I am trying to do is allow a user to click the link and...
1
by: Ben | last post by:
Hi, I'm designing a c# page and trying to add a checkbox column to a GridView, I've added a Template Row (as described at: http://aspnet.4guysfromrolla.com/articles/052406-1.aspx) and in the...
1
by: Danielle | last post by:
Greetings all and thanks in advance for any help you can provide. I am trying ultimately to get values from a gridview row when a checkbox on the row is checked. the problem I'm having is that...
1
by: janetb | last post by:
I have a gridview with an update capabilities - a textbox column (roomName), a dropdownlist(orgID), a dropdownlist(roomTypeID),a checkbox column (dialOut), a checkbox column (dialIn). When I try to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.