Asp.net 如何使用GridView控件的DeleteCommand和UpdateCommand?

2020-04-17 社会 158阅读



Text="删除" OnClientClick="return confirm('是否删除?')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
// cs 代码
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
string username = (this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text;
string sql = "update feeinfo set username='" + username + "' where id=" + id + "";
if (connection.ExecutUpdate(sql))
{
GridView1.EditIndex = -1;
// DataBind();
bind(""); //绑定数据
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id=int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
string sql = "delete from feeinfo where id="+id+"";
if (connection.ExecutUpdate(sql))
{
Response.Write("