473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to bind checkbox with gridview in asp.net 2.0

1
How to bind checkbox with gridview in asp.net 2.0

I take a gridview control and bind data dynamicaly using code.I taken backend tool as a Ms Access and now I want to add new column with checkbox so user can delete selected recored..So How can I bind checkbox with gridview...
Dec 19 '07 #1
1 13877
Frinavale
9,735 Expert Mod 8TB
How to bind checkbox with gridview in asp.net 2.0

I take a gridview control and bind data dynamicaly using code.I taken backend tool as a Ms Access and now I want to add new column with checkbox so user can delete selected recored..So How can I bind checkbox with gridview...
You need to add a TemplateField to your GridView so that it generates a checkbox per row.

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField>
  2.     <EditItemTemplate>
  3.         <asp:CheckBox ID="Chkbx_Selected" runat="server" />
  4.     </EditItemTemplate>
  5.      <ItemTemplate>
  6.          <asp:CheckBox ID="Chkbx_Selected" runat="server" />
  7.     </ItemTemplate>
  8.  </asp:TemplateField>
You can easily do this in your design view of your GridView.
When you have selected your GridView in design mode, you will see something that looks like a play button in the top right hand corner (a triangle).

Click it and a menu will appear.
From this menu click the Add Columns.
Select the CheckBoxField from the "Available Fields" section.
Click the Add button.
In the CheckBoxField properties, give the check box a name (like "Chkbx_Selected") so that you can find the control in your .NET code that is responsible for deleting the entry.

This will display check boxes next to each row in your GridView.

Now when you are performing the delete you need to loop through each row in your GridView, get the check box, and determine whether or not to delete that row...

eg
Expand|Select|Wrap|Line Numbers
  1. For Each dr In MyGridView.Rows
  2.     Dim chkbox as CheckBox = dr.FindControl("Chkbx_Selected")
  3.     If chkbox.Checked = True
  4.         'Delete the entry.
  5.     End If
  6. Next
  7.  
Cheers!

-Frinny
Dec 19 '07 #2

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 ...
0
by: GMartin | last post by:
I have a pop-up form with a three columned Grid that has checkboxes in a Template Column in the first/left-most column. (The form is to allow users to select "Members" of a group, where they check...
3
by: mercea | last post by:
hi all, i have inserted a checkboxlist in my gridview using the <item template>. but i want the checkbox text to be genarated at runtime i.e via textboxes(user input). i have 5 textboxes and 5...
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...
0
by: dotnetrookie | last post by:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have 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...
0
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...

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.