473,888 Members | 1,636 Online
Bytes | Software Development & Data Engineering Community
+ 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 2443

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

Similar topics

1
2897
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 properties and Item Style to the column but it has no effect. Is there someway to size this column to be smaller? I removed the CssClass property and it had no effect on the size as well. 2. The gridview is sortable using javascript. Is there...
0
3307
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 it happens when i add it to the gridview. why is that ? i have added checkbox like this in my gridview: .......
1
21480
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 the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. Unfortunate Outcome: Each checkbox returns false for its attribute:checked whether the user has placed a...
9
5543
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 another page)..i have been google around and found this.... If e.Row.RowType = DataControlRowType.DataRow Then Dim Chk As CheckBox = e.Row.FindControl("CheckBox1") just dont know what to do next...Any ideas?
2
5145
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 Checkbox Text2 Checkbox Text3 Checkbox Text4 Checkbox
3
1899
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 have all records in the same group be selected by setting the checkbox's to checked for just that group. Can this be done? And can someone point me in the right direction?
1
2398
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 Edit Templates dragged a Checkbox into the Item Template. The new column shows up, but it's empty...no checkbox appears. Any ideas? here's the source if it helps:
1
4174
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 after ticking the checkbox, the whole page refreshes (expectedly), the checkbox is unmarked and the response.write message displayed below never displays. It follows that if I uncomment the lines that try to capture the value in cell(3) and...
1
3798
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 add another checkbox column, the sql database isn't updated properly with a 0/1 or false/true but with null. I've tried everything I can think of. Can anyone help? Data command stuff: UpdateCommand="update telehealth.dbo.xTblRoom...
0
9961
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10438
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3251
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.