单击按钮删除网格行 [英] Deleting grid row on Button click

查看:83
本文介绍了单击按钮删除网格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何通过单击放置在该网格中的按钮来删除网格中的行!

谢谢您!!!!

Hi,
How to delete row of Grid on click of button placed in that Grid!!

thanx for suggestions!!!

推荐答案

您不会从网格中删除,而是从绑定到网格的数据源中删除并重新绑定到网格.如果您阅读GridView文档,则会发现一种删除行的特定方法.
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.


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;
	}
  }


protected void gvLoad_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    dt = tblGridRow();
    dt.Rows.RemoveAt(e.RowIndex);
    gvLoad.DataSource = dt;
    gvLoad.DataBind();



}


这篇关于单击按钮删除网格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆