protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "0")
{
e.Row.Cells[4].Text = "未审核";
}
else
{
e.Row.Cells[4].Text = "<font color=red>已审核</font>";
}
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "0")
{
e.Row.Cells[4].Text = "未审核";
}
else
{
e.Row.Cells[4].Text = "<font color=red>已审核</font>";
}
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
}
}
如果e的Row的RowType==DataControlRowType的DataRow?
...
另外给每行的第七列即e.Row.Cells[6]控件的单击事件加上确认提示。
//看这方法名, 应该是让 GridView 在绑定数据事件时触发该方法
{
if (e.Row.RowType == DataControlRowType.DataRow)
//是否如果控件类型相符
{
if (e.Row.Cells[4].Text == "0")
{
//是否如果该行的第5列(0是第一列)的文本为 0
e.Row.Cells[4].Text = "未审核";
//该行文本设置为 "未..."
}
else
{
e.Row.Cells[4].Text = " <font color=red> 已审核 </font> ";
//该行文本设置为 "已...", 而且是红色字字, 这个FONT已是过时了, 建议使用<span style="color:red"></span>
}
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
//为该行的第7列的第一个控件添加 onclick 事件, 内容为点击触发时, 弹出消息框, 内容是"确定..吗?", 消息框类型是选择消息框.
}
}okay?!
-----------------------
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
e.row.cells[6].controls[0]//表示该行的行7列的第1个控件.
((LinkButton)(e.Row.Cells[6].Controls[0]))
//这一行多余了一对括号, 写成 ((LinkButton)e.Row.Cells[6].Controls[0])就行了.
//意思是将 该行的行7列的第1个控件 强制转换为 LinkButton 类型.
.....Attributes.Add("onclick", "return confirm('确定删除吗?')");
//为控件的属性添加一个名为 onclick, 内容为 return confirm('确定删除吗?')
// onclick 是点击事件
// confirm 是JAVASCRIPT默认函数, 将是弹出确认消息框.//---------------楼主需要好好学习基础.okay?!