首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

但点击编辑时出现System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围的异常

2012-01-19 
但点击编辑时出现System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围的错误.protectedvoi

但点击编辑时出现System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围的错误.
protected   void   GridView1_RowDataBound(objectsender,GridViewRowEventArgs   e)
        {
                if   (e.Row.RowType   ==   DataControlRowType   .DataRow     )
                {
                  ((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add( "onclick ",   "return   confirm( '你确认删除吗? '); ");
                    ((LinkButton)(e.Row.Cells[7].Controls[0])).Attributes.Add( "onclick ",   "return   confirm( '你确认编辑吗? '); ");
                   
                }
          }
但点击编辑时出现System.ArgumentOutOfRangeException:   指定的参数已超出有效值的范围的错误.
要是把((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add( "onclick ",   "return   confirm( '你确认删除吗? '); ");注释起来就可以编辑了.
这是为什么呀?????????????//
请高手指点.


[解决办法]
建议不要使用索引定位: e.Row.Cells[6].Controls[0],只要你的列一增删改,改索引就要同步更新,很试麻烦

应该使用 FindControl 方法,不容易出错

LinkButton lnk = e.Row.FindControl( "要查找的LinkButton的ID ") as LinkButton;
lnk.Attributes.Add( "onclick ", "return confirm( '你确认删除吗? '); ");


热点排行