我用以下方法给gridview中自带的删除按钮添加了确认信息
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton delbtn = (LinkButton)e.Row.Cells[4].Controls[2];
delbtn.Attributes.Add("onclick", "javascript:return confirm('确定要删除吗?');");
}
}
但是这样有个问题,在进入编辑模式后,点取消进也会弹出确认信息。
请问怎么解决啊???
------------------------
解决了
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow&&GridView1.EditIndex==-1)
{
LinkButton delbtn = (LinkButton)e.Row.Cells[4].Controls[2];
delbtn.Attributes.Add("onclick", "javascript:return confirm('确定要删除吗?');");
}
}
呵呵,楼主这个判断好,GridView1.EditIndex==-1