为什么加了这句下面之后点击编辑会出现指定的参数已超出有效值的范围。参数名: index的错误。点击删除能够进行删除且有弹窗。把这句去掉,编辑功能正常运行。
编辑按钮在单元格6,删除按钮在单元格7
aspx.cs代码
for (int i = 0; i < GridView1.Rows.Count; i++)
{
((LinkButton)GridView1.Rows[i].Cells[6].Controls[0]).Attributes.Add("onclick", "return confirm('are you sure to delete it?')");
}
aspx代码:
<asp:CommandField ButtonType="Button" HeaderText="编辑" ShowEditButton="True" ShowHeader="True" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" ShowHeader="True"/>