您的位置:首页 > 其它

GridView实现删除时弹出确认对话框

2009-02-03 11:38 627 查看


//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 这些都不会显示出姓名!

答:因为你已经用了TemplateField啊!
这表明GridView已不再存在第一列数据显示了。所以当前Text当然为空咯。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: