//GridView实现删除时弹出确认对话框
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//GridView实现自动编号:
//注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。
//if (e.Row.RowIndex != -1)
//{
// int id = e.Row.RowIndex + 1;
// e.Row.Cells[0].Text = id.ToString();
//}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow) //如果行的类别是数据行,就执行
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Selected)
{
//((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:ID号为/" " + e.Row.Cells[0].Text.ToString().Trim() + " /"的员工档案吗?')");
((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:姓名为/" " + e.Row.Cells[1].Text.ToString().Trim() + " /"的员工档案吗?')");
}
}
}
//GridView实现删除时弹出确认对话框
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//GridView实现自动编号:
//注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。
//if (e.Row.RowIndex != -1)
//{
// int id = e.Row.RowIndex + 1;
// e.Row.Cells[0].Text = id.ToString();
//}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow) //如果行的类别是数据行,就执行
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Selected)
{
//((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:ID号为/" " + e.Row.Cells[0].Text.ToString().Trim() + " /"的员工档案吗?')");
((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:姓名为/" " + e.Row.Cells[1].Text.ToString().Trim() + " /"的员工档案吗?')");
}
}
}
注意:e.Row.Cells[1].Text.ToString().Trim() 这里的列一定要是 BoundField
如<asp:BoundField DataField="User_name" HeaderText="姓名" />
而不能是TemplateField 或 HyperLinkField 这些都不会显示出姓名!