ASP.NET GridView 使用 关于显示、更新、删除
ASP.NET GridView 使用 显示、更新、删除
删除:
获取要删除行的某个主字段:int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex]["id"].ToString());
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex]["id"].ToString());
string sql = "delete from messages where [id]=" + id;
int n;
n = DBManage.Command(sql);
if (n > 0)
{
Response.Write("<script language=javascript>function window.onload(){alert('删除成功');location.href='adminIndex.aspx'}</script>");
}
else
{
Page.RegisterStartupScript("alert", "<script lanauage='javascript'>alert('删除失败!')</script>");
}
}
posted on 2010-11-12 16:53 Henry_Wang 阅读(240) 评论(0) 编辑 收藏 举报