•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,687 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,207 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1049 | Replies: 5
![]() |
•
•
Join Date: Dec 2006
Location: United States
Posts: 612
Reputation:
Rep Power: 3
Solved Threads: 14
First add this code on the .aspx file to add checkboxes to GridView
<asp:TemplateField HeaderText="Delete" ShowHeader="False">
<ItemTemplate>
<asp:CheckBox ID="chkDeleteRows" runat="server"/>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</FooterTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
Then locate
protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e) for your GridView and place the code below.
// Looping through all the rows in the GridView
foreach (GridViewRow row in gv.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("chkDeleteRows");
//Check if the checkbox is checked.
if (checkbox.Checked)
{
// Pass the Row ID to the DeleteList function
DeleteList(Convert.ToInt32(gv.DataKeys[row.RowIndex].Values[0]));
// DataKeys should be defined in the GridView property on the aspx page along with the delete button handler like this (OnRowDeleting="gv_RowDeleting")
// DataKeyNames="ROWID" (this should be the Primary Key in the table.)
}
}
<asp:TemplateField HeaderText="Delete" ShowHeader="False">
<ItemTemplate>
<asp:CheckBox ID="chkDeleteRows" runat="server"/>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</FooterTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
Then locate
protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e) for your GridView and place the code below.
// Looping through all the rows in the GridView
foreach (GridViewRow row in gv.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("chkDeleteRows");
//Check if the checkbox is checked.
if (checkbox.Checked)
{
// Pass the Row ID to the DeleteList function
DeleteList(Convert.ToInt32(gv.DataKeys[row.RowIndex].Values[0]));
// DataKeys should be defined in the GridView property on the aspx page along with the delete button handler like this (OnRowDeleting="gv_RowDeleting")
// DataKeyNames="ROWID" (this should be the Primary Key in the table.)
}
}
•
•
Join Date: May 2008
Posts: 10
Reputation:
Rep Power: 1
Solved Threads: 0
sir this thing is not working, basically i'm facing a prob because of Direct Cast and Find control. when i'm writing a cond for checking checkbox is checked or not then it is always coming false. i don't know how to use find control or direct cast for this condition. please help me. i'm in very much prob
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
Other Threads in the ASP.NET Forum
- Previous Thread: create sqldatasource through coding
- Next Thread: OLE window application in web site


Linear Mode