Pages

Subscribe:

Ads 468x60px

Saturday, March 10, 2012

how to delete multiple rows in a gridview in asp.net using c#

In this web programming tutorial we will learn that how we can delete multiple rows of gridview in asp.net using c#.
just copy and paste the code and use it as per your requirements.
Code for .aspx file
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

code for aspx.cs file
protected void Button1_Click(object sender, EventArgs e)  
{  
  
foreach(GridViewRow row in GridView1.Rows)  
{  
                  CheckBox chkbox = (CheckBox)row.FindControl("chkid");  
                  string uid = chkbox.Text;  
                  if (chkbox.Checked)  
                  {  
  
  
                   con.ConnectionString=strcon;  
                   com.Connection=con;  
                   con.Open();  
                   string query = "Delete from users where User_ID='"+uid+"'";  
                   com.CommandText = query;  
                   com.ExecuteNonQuery();  
                   con.Close();  
                  fillgrid();  
  
               }  
}  
  
}  

No comments:

Post a Comment