AspdotnetCodes.com
Voted 'Best ASP.NET Host' for 2008 – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 Gridview with checkbox
Posted by boda.raju on  6/18/2008 8:39:27 AM Category: ADO.NET
Add to my favorites
Email to friend
  
i am placed checkbox in gridview through source code ,and take delete button outside if i click on checkbox then press delete button that row delete in database, how is it possible ?
(plz send ans:)
delete code:
foreach (GridViewRow row in GridView1.Rows)
{

CheckBox cb = (CheckBox)row.FindControl("cb");
if (cb .Checked )
{
//how to write delete code (plz write wht iam write, iam write delte code but it error)
}

Post Answer Post New Question

 Viewer's Answers
Delete Code is Here
Posted By Moderator1 on 6/20/2008 8:46:00 PM
Description:
foreach (GridViewRow row in GridView1.Rows)
{

CheckBox cb = (CheckBox)row.FindControl("cb");
if (cb .Checked )
{
string sql="Delete from yourtable where id='"& row.cells[0].Text &"'";
SqlCommand cmd=new SqlCommand(sql,connobject);
cmd.ExecuteNonQuery();
}
}

this above code inside the block is only a sample code to guide you. Same like that you do the real one.
Thanks.
 
Sponsored by