Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to delete row of Grid on click of button placed in that Grid!!

thanx for suggestions!!!
Posted

You don't delete from the grid, you delete from the datasource it is bound to and rebind to the grid. If you read the GridView documentation you will find a specific method for deleting rows.
 
Share this answer
 
C#
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
	try
	{
	string constr = @"Data Source=SQLEXPRESS2008;Initial Catalog=Database;Integrated Security=True";
	string query = "DELETE FROM Table_Name WHERE 1st_column=@a";
 
	SqlConnection con = new SqlConnection(constr);
	SqlCommand cmd = new SqlCommand();
 
	cmd.Parameters.Add("@a", SqlDbType.Int).Value = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text)";
	cmd.Connection = con;
 
	con.Open();
	cmd.ExecuteNonQuery();
 
	con.Close();
	BindData();
	}
	catch(Exception ex)
	{
	    throw ex;
	}
  }
 
Share this answer
 
v2
Comments
qasimidl 29-Mar-12 6:39am    
i am working Infragestic " UltraWebGrid"
not asp.net gridview
C#
protected void gvLoad_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    dt = tblGridRow();
    dt.Rows.RemoveAt(e.RowIndex);
    gvLoad.DataSource = dt;
    gvLoad.DataBind();



}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900