首页 新闻 赞助 找找看

about GridView Question

0
悬赏园豆:5 [已关闭问题] 关闭于 2014-07-25 10:28

为什么我直接写

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewControl.GridViewBackColorChange(GridView1, e);
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != -1)
{
((HyperLink)e.Row.FindControl("lb_Prt")).Attributes.Add("onclick", "window.open('PackSettleReportView.aspx?CWNO=" + this.GridView1.DataKeys[e.Row.RowIndex].Values["CWNO"].ToString() + "','','resizable:yes;scroll:no;status:no;dialogWidth=600px;dialogHeigth=300px;center=yes;help=no')");
}
}

这个不会报错

而我把这个封装起来在一个类中

public static void GridViewBackColorChange(GridView sender, GridViewRowEventArgs e,string url,string value,string paras)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != -1)
{
((HyperLink)e.Row.FindControl("lb_Prt")).Attributes.Add("onclick", "window.open('" + url + "?" + value + "=" + paras + "','','resizable:yes;scroll:no;status:no;dialogWidth=600px;dialogHeigth=300px;center=yes;help=no')");
}
else
{
throw new Exception();

}

}

然后在一个页面的GridView1_RowDataBound中调用这个事件却报错:

用户代码未处理 System.ArgumentOutOfRangeException
Message=索引超出范围。必须为非负值并小于集合大小。
参数名: index
Source=mscorlib
ParamName=index
StackTrace:
在 System.Collections.ArrayList.get_Item(Int32 index)
在 System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
在 PuTaoYuan.Web.FinanceDep.PackageBilling.GridView1_RowDataBound(Object sender, GridViewRowEventArgs e) 位置 C:\Users\yushuai\Desktop\CodematicDemo123\Web\FinanceDep\PackageBilling.aspx.cs:行号 57
在 System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e)
在 System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
在 System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
在 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
在 System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
在 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
在 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
在 System.Web.UI.WebControls.DataBoundControl.PerformSelect()
在 System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
在 System.Web.UI.WebControls.GridView.DataBind()
在 PuTaoYuan.Common.Bind.BindGridview(GridView grv, DataTable dt) 位置 C:\Users\yushuai\Desktop\CodematicDemo123\Common\Bind.cs:行号 39
在 PuTaoYuan.Web.FinanceDep.PackageBilling.BIndGridView1() 位置 C:\Users\yushuai\Desktop\CodematicDemo123\Web\FinanceDep\PackageBilling.aspx.cs:行号 26
在 PuTaoYuan.Web.FinanceDep.PackageBilling.Page_Load(Object sender, EventArgs e) 位置 C:\Users\yushuai\Desktop\CodematicDemo123\Web\FinanceDep\PackageBilling.aspx.cs:行号 18
在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
在 System.Web.UI.Control.OnLoad(EventArgs e)
在 System.Web.UI.Control.LoadRecursive()
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

索引 其实并没超出范围这是为什么了?

IT_小子的主页 IT_小子 | 初学一级 | 园豆:17
提问于:2014-07-21 10:08
< >
分享
所有回答(1)
0

你对比下 Attributes.Add 的第二个参数的值是不是相同的。

Launcher | 园豆:45045 (高人七级) | 2014-07-21 10:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册