Click here to Skip to main content
15,883,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add a checkbox in Gridview ???


Can someone please teach me how to add a checkbox in gridview?

i added from the add new columns,but the checkbox is not fuctioning when i run my page,means it can't be check

can someone please teach me in detail?coz i am new in ASP.Net 2.0 ( Using Visual Studio 2013)

and if possible,i wan to retrieve 1 of the column value of the database row which being checked

can someone teach me this as well?

thanks[:)]
Posted

XML
You need to define a checkbox column as a TemplateField.

Below is an example showing how to retrieve the key of each checked item.

CheckBoxExample.aspx
view sourceprint?
01 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxExample.aspx.cs" Inherits="CheckBoxExample" %>

02

03 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

04

05 <html xmlns="http://www.w3.org/1999/xhtml" >

06 <head runat="server">

07     <title>CheckBox Example</title>

08 </head>

09 <body>

10     <form id="form1" runat="server">

11     <div>

12         <asp:GridView ID="ProductGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ItemId">

13             <Columns>

14                 <asp:BoundField DataField="ItemDescription" DataFormatString="{0}" HeaderText="Item" />

15                 <asp:BoundField DataField="ItemPrice" DataFormatString="{0:C}" HeaderText="Price" />

16                 <asp:TemplateField HeaderText="Purchase">

17                     <ItemTemplate>

18                         <asp:CheckBox ID="CheckBoxPurchase" runat="server" Enabled="true" />

19                     </ItemTemplate>

20                 </asp:TemplateField>

21             </Columns>

22         </asp:GridView>

23         <asp:Button ID="Purchase" runat="server" Text="Purchase Checked Items" />

24     </div>

25     </form>

26 </body>

27 </html>
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900