ASP.NET(C#)如何实现datagridview中选择行编辑行,删除等操作
来源:百度知道 编辑:UC知道 时间:2024/09/21 10:41:38
//删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sid = GridView1.Rows[e.RowIndex].Cells[0].Text;
SqlConnection conn = com.GetConn();
SqlCommand comm = new SqlCommand("delete from 表名 where id=@id", conn);
comm.Parameters.AddWithValue("@id", sid);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
//刷新页面
setdata();
}
void setdata()
{
SqlConnection conn = com.GetConn();
SqlCommand comm = new SqlCommand("select * from 表名", conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable table = new DataTable();
da.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}
那些事件是在RowEditing(这个是修改的事件,要是修改 就在这里编写) 删除的事件是在RowDel