AspdotnetCodes.com
US and UK Data Centers – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 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 Answer Post New Question

 Viewer's Answers
Write delete code in Delete Button Event
Posted By Moderator1 on 6/17/2008 8:43:39 PM
Description:
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.
 
Sponsored by