protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}其中的Controls[0]是什么意思,我刚刚学习。net,望高手不吝赐教,谢谢!!
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}其中的Controls[0]是什么意思,我刚刚学习。net,望高手不吝赐教,谢谢!!
// GridView控件的数据绑定事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// 如果当前行是数据绑定行
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 从当前行的第三个单元格中找到第一个默认的控件,添加客户端脚本的onclick事件
((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
其实简单来说,就是你的GridView列表第三列的删除按钮,添加一个确认删除的对话框。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//判断是否数据绑定行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Cells[2].Controls[0] 找出第三列里第一个控件,把它转换 LinkButton 对象 并添加一个 onclick Js事件
((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}