AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 gridview
Posted by boda.raju on  6/16/2008 3:29:24 PM Category: ADO.NET
Add to my favorites
Email to friend
iam placed checkbox in gridview if i click on checkbox then press delete button that row delete in database, how is it possible ?
plz send code for that(delete button code)

Post Your Reply Post New Question

 Viewer's Reply
Write delete code in Delete Button Event
Answered By Moderator1 on 6/17/2008 8:43:39 PM
Hi,

As per my understanding, you want to select the check box in the GridView, then when you click Delete Button, it should delete the rows.

So you have to loop through the GridView rows and find the check box and its corresponding value then perform Delete operation.

The sample code is

protected void BtnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in GridView1.Rows)
{
CheckBox CheckBox1 = (CheckBox)gvrow.FindControl("CheckBox1");
if (CheckBox1.Checked)
{
//Response.Write("Deleted");
// Do all you Delete operations in this block.
}
}
}

You can choose a single check box or you a select multiple check boxes also for Deleting records in your GridView control.

Thanks and have a nice time.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)
SearchSAP