同编辑按钮添加一样,将删除命令“Delete”绑定到该按钮,并添加删除事件:
代码
string
strID
=
GridView2.DataKeys[e.RowIndex].Value.ToString();
string strSQL;
int id = 0 ;
strSQL = " Delete from userliuyan WHERE lId = " + strID;
try
{
id = ws.ExcuteSql(strSQL, CommandType.Text, null );
}
catch (Exception)
{
throw ;
}
ClientScript.RegisterStartupScript(GetType(), " Message " , " <SCRIPT LANGUAGE='javascript'>alert('删除成功!');</script> " );
string strSQL1 = "" ;
strSQL1 = " select * from userliuyan " ;
try
{
GridView2.DataSource = ws.GetWritersBig(strSQL1, CommandType.Text, null );
GridView2.DataBind();
}
catch (Exception)
{
throw ;
}
string strSQL;
int id = 0 ;
strSQL = " Delete from userliuyan WHERE lId = " + strID;
try
{
id = ws.ExcuteSql(strSQL, CommandType.Text, null );
}
catch (Exception)
{
throw ;
}
ClientScript.RegisterStartupScript(GetType(), " Message " , " <SCRIPT LANGUAGE='javascript'>alert('删除成功!');</script> " );
string strSQL1 = "" ;
strSQL1 = " select * from userliuyan " ;
try
{
GridView2.DataSource = ws.GetWritersBig(strSQL1, CommandType.Text, null );
GridView2.DataBind();
}
catch (Exception)
{
throw ;
}
因为这些按钮可以像普通按钮一样进行属性设置:
比如,如果我们要添加提示对话框,可在该按钮的属性,OnClicentClick属性中添加:return confirm('确定删除?')。