Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
CODE Adding Checkbox to Datagrid1

CODE Adding Checkbox to Datagrid1

Ratings: (0)|Views: 25 |Likes:
Published by api-27182084

More info:

Published by: api-27182084 on Oct 14, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

There are many instances when we require a webcontrol like a checkbox to be added to a datagrid for
performing different operations like adding or deleting records available in a datagrid(from a shopping cart or
a mailbox).

This articles demonstrates how to add a checkbox to a datagrid and read whether the checkbox is checked
for each of the records present in the datagrid and perform specific action on them.

Code below shows a datagrid which contains a checkbox column and a checkbox column is added to the
datagrid within the TemplateColumn tag and precisely in the ItemTemplate tag of the datagrid. It is added as
a normal checkbox server control.

<form id="DG_Controls_Example" method="post" runat="server">
<asp:DataGrid id="DGSample" runat="server" AllowPaging="True"

AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Contactname"

HeaderText="Customer Name"></asp:BoundColumn>
<asp:BoundColumn DataField="CompanyName"
HeaderText="Company Name"></asp:BoundColumn>
<asp:BoundColumn DataField="ContactTitle"

HeaderText="Title"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkbox" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

</asp:DataGrid>

<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</form>

In this example we have added a button to read all the records which have been selected by checking the
respective boxes in each record and display the checked records.
In the code behind, we bind the data to the datagrid as shown below:
private void Page_Load(object sender, System.EventArgs e)

{
if(!Page.IsPostBack)
{

adp = new SqlDataAdapter("Select * from

customers",con);
ds= new DataSet();
adp.Fill(ds);
DGSample.DataSource=ds;
DGSample.DataBind();

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->