当我在GridView1_RowDataBound 的事件中写删除确认的代码时,点编辑就会出现这样的错误:
指定的参数已超出有效值的范围。
参数名: index 
 if (e.Row.RowType == DataControlRowType.DataRow)
        {     LinkButton delBtn = (LinkButton)e.Row.Cells[9].Controls[0];----这行
            delBtn.Attributes.Add("onclick", "return confirm('确认删除吗?');");
        }
请问是什么原因
还有顺便解释一下 e.Row.RowType == DataControlRowType.DataRow 这句什么意思?谢谢了

解决方案 »

  1.   

    当我在GridView1_ItemDataBound 的事件中写删除确认的代码时,点编辑就会出现这样的错误:
    指定的参数已超出有效值的范围。
    参数名: index 
     if (e.Item.ItemIndex==9)
            {
                e.Item.Attributes.Add("onclick", "return confirm('确认删除吗?');");
            }
      

  2.   

    e.Row.RowType == DataControlRowType.DataRow 能解释下这句什么意思吗 
      

  3.   

    if (e.Item.ItemIndex==9)
            {
                e.Item.Attributes.Add("onclick", "return confirm('确认删除吗?');");
            }
    -----------------
    这个不行
      

  4.   

    http://www.cnblogs.com/califord/category/76812.html
    这里全有了
      

  5.   

    datagrid 和gridview  有区别的把
      

  6.   

    使用列索引和控件索引会因为添加删除列或控件而使程序出错
    如在命令列同时使用了编辑和删除,并且编辑在删除前面时
    点击了编辑而第二个链接变成了取消,导致点击取消出现确认信息
    而用FindControl则有可能点击编辑后删除链接变成了取消链接
    导致程序运行出错我的解决方法是把命令列转换成模板,直接在模板里给删除链接加OnClientClick<asp:TemplateField HeaderText="操作" ShowHeader="False">
    <EditItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
    Text="更新" ValidationGroup="EditValidation"></asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
    Text="取消"></asp:LinkButton>
    </EditItemTemplate>
    <ItemStyle Width="20%" />
    <ItemTemplate>
    <asp:LinkButton ID="edit" runat="server" CausesValidation="False" CommandName="Edit"
    Text="编辑"></asp:LinkButton>
    <asp:LinkButton ID="delete" runat="server" CausesValidation="False" CommandName="Delete"
    Text="删除" OnClientClick="return confirm('您确定要删除选中的内容吗?');"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
      

  7.   

    多谢 purexu(NetRube的马甲)  问题解决