“”应用程序中的服务器错误“索引超出范围.必须为非负数且小于集合参数 name:index 的大小
本文关键字:小于 集合 name index 参数 服务器 应用程序 错误 索引 范围 | 更新日期: 2023-09-27 18:35:35
>"索引超出范围。必须为非负数且小于集合参数 name:index 的大小。这是一个截图:这是我的应用程序的错误,当我选择要打印的文档时,应用程序将随机打印其他文档。请:(师傅需要您的帮助这是我的代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
trackingDataContext dc = new trackingDataContext(MyClass.conn);
if (e.CommandName == "Print")
{
int row = Int32.Parse(e.CommandArgument.ToString()) + (GridView1.PageIndex * GridView1.PageSize);
GridViewRow gr = GridView1.Rows[row];
string ID = gr.Cells[0].Text;
string jenis_dokumen = gr.Cells[2].Text;
string nopek = gr.Cells[4].Text;
string rdl = "";
var td = (from t in dc.tracking_dokumens where t.id == Convert.ToInt16(ID) select t).SingleOrDefault();
var area = (from a in dc.field_lists where a.id == td.field_id select a).SingleOrDefault();
if (area.field_name == "Kantor Pusat Jakarta")
{
if (jenis_dokumen == "SPD")
{
rdl = "deklarasi.rdl";
}
else if (jenis_dokumen == "Panjar Dinas")
{
rdl = "panjar_dinas.rdl";
}
else if (jenis_dokumen == "Pengajuan Panjar Kerja")
{
rdl = "panjar_kerja.rdl";
}
else if (jenis_dokumen == "SP3")
{
rdl = "sp3.rdl";
}
else if (jenis_dokumen == "Pertanggungjawaban Panjar Kerja")
{
rdl = "pertanggungjawaban.rdl";
}
}
else
{
if (jenis_dokumen == "SPD")
{
rdl = "deklarasi_area.rdl";
}
else if (jenis_dokumen == "Panjar Dinas")
{
rdl = "panjar_dinas_area.rdl";
}
else if (jenis_dokumen == "Pengajuan Panjar Kerja")
{
rdl = "panjar_kerja_area.rdl";
}
else if (jenis_dokumen == "SP3")
{
rdl = "sp3_area.rdl";
}
else if (jenis_dokumen == "Pertanggungjawaban Panjar Kerja")
{
rdl = "pertanggungjawaban_area.rdl";
}
}
Response.Redirect(MyClass.Site + "/_layouts/ReportServer/RSViewerPage.aspx?rv:RelativeReportUrl=/sites/tracking/Report/"+rdl+"&Source="+MyClass.Site+"/Report/Forms/AllItems.aspx&DefaultItemOpen=1&rp:nopek="+nopek+"&rp:id="+ID);
}
}
检查发生异常的索引和数组大小。您显然正在尝试获取索引上的负数或超过(数组中的项目数 - 1)。