System.IndexOutOfRangeException: 索引超出了数组界限。

xhy_0423 2006-07-13 05:34:23
“/OilTransaction”应用程序中的服务器错误。
--------------------------------------------------------------------------------

索引超出了数组界限。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.IndexOutOfRangeException: 索引超出了数组界限。

源错误:


行 190: if(e.CommandName=="DeptDetail")
行 191: {
行 192: DataGrid2Bind(DataGrid1.DataKeyField[e.Item.ItemIndex]);
行 193: }
行 194:


源文件: c:\inetpub\wwwroot\oiltransaction\houses\virescence\list.aspx.cs 行: 192

堆栈跟踪:


[IndexOutOfRangeException: 索引超出了数组界限。]
System.String.get_Chars(Int32 index) +20
OilTransaction.Houses.Virescence.List.DataGrid1_ItemCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\oiltransaction\houses\virescence\list.aspx.cs:192
System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1277




--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573

这个用于一个DataGrid1超链列链接到一个DataGrid2上,要传递一个DataGrid1的参数。超链列的
CommandName=="DeptDetail"。不知道错在哪里?
...全文
512 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xhy_0423 2006-07-14
  • 打赏
  • 举报
回复
//----显示/隐藏查询表单域事件方法-----------------
private void IbtnShowSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(PanelSearch.Visible)
{
PanelSearch.Visible = false;
IbtnShowSearch.ImageUrl = "../../Images/Kilimanjaro/text_next.gif";
}
else
{
PanelSearch.Visible = true;
IbtnShowSearch.ImageUrl = "../../Images/Kilimanjaro/text_prev.gif";
}
}

//---打开查询条件管理页按钮事件方法---------------
private void BtnStrSearchSave_Click(object sender, System.EventArgs e)
{
if(Session["strSearch"] == null)
{
MessageBox.Show(this,"没有要保存的查询条件");
return;
}
string strtemp = Server.UrlEncode(Session["strSearch"].ToString());
Response.Write("<script>showModalDialog(\"../../CommonPage/SearchManage.aspx?ModuleName="+ModuleName+"&SearchString="+strtemp+"\",\"\",\"menubar=no;toolbar=no;statebar=no;DialogWidth:600px;DialogHeight:400px\")</script>");

// Repeater1Bind();
}

//----------查询条件列表事件方法--------------------
private void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
if(e.CommandName == "LinkSearch")
{
if(e.CommandArgument != null)
{
strSearch = e.CommandArgument.ToString();
DataGrid1Bind();
Session["StrSearch"] = strSearch;
}
}
}
xhy_0423 2006-07-14
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace OilTransaction.Houses.Virescence
{
/// <summary>
/// List 的摘要说明。
/// </summary>
public class List : System.Web.UI.Page
{
//-----------类变量定义-------------------------------------
//
//本模块的名称
//
public const string ModuleName="Virescence";
//
//查询条件
//
private string strSearch;
//
//逻辑变量实例
//
private OilTransaction.BLL.House.House_VirescenceChild bll;
//-----------------------------------------------------------

protected System.Web.UI.WebControls.ImageButton IbtnShowSearch;
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label Label3;
protected Sdtcn.WebControl.SqlPager SqlPager1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox txtLocus;
protected System.Web.UI.WebControls.DropDownList LstSubDept;
protected System.Web.UI.WebControls.Panel PanelSearch;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button BtnStrSearchSave;
protected System.Web.UI.WebControls.DataGrid Datagrid2;
protected Sdtcn.WebControl.SqlPager SqlPager2;
protected System.Web.UI.HtmlControls.HtmlInputHidden val;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

bll = new OilTransaction.BLL.House.House_VirescenceChild();

if(!this.IsPostBack)
{
//--------------------------------------
//页面初始控件设置
//--------------------------------------
PanelSearch.Visible = false;
//--------------------------------------

//---页面传递一个任意值的参数时,保存查询条件到用户状态中,若无,则设置为空-----------
if(Request.QueryString["SaveView"] == null)
Session["StrSearch"] = null;

//--确定当前用户时候保存有查询的条件,有则按条件获取记录,若无则全部显示----
if(Session["StrSearch"] != null)
strSearch = Session["StrSearch"].ToString();
else
strSearch = string.Empty;
//---------------------------------------------------------------------

//--------------------------------------
// 页面初始数据绑定
//--------------------------------------
DataGrid1Bind();
Repeater1Bind();
// DataGrid2Bind(9);
LstDeptBind();
//--------------------------------------
}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

#region 数据绑定
private void DataGrid1Bind()
{
SqlPager1.RecordCount =bll.GetList(string.Empty).Tables[0].Rows.Count;
DataSet ds = bll.GetViewList(SqlPager1.ItemsPerPage,SqlPager1.CurrentPageIndex+1,"1=1"+strSearch);
DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataKeyField ="DepID";
DataGrid1.DataBind();
}
private void LstDeptBind()
{
LstSubDept.DataSource=(new OilTransaction.BLL.Administration.Department()).GetList(string.Empty).Tables[0];
LstSubDept.DataTextField="DeptName";
LstSubDept.DataValueField="DeptID";
LstSubDept.DataBind();
ListItem ul= new ListItem();
ul.Text = "全部";
ul.Value = "-1";
ul.Selected = true;
LstSubDept.Items.Add(ul);
}
//---查询条件数据绑定------
private void Repeater1Bind()
{
OilTransaction.BLL.SearchInfo searchBll = new OilTransaction.BLL.SearchInfo();
string strWhere = " and UserID='"+ User.Identity.Name +"' and ModuleName='" + ModuleName + "'";
DataSet ds = searchBll.GetList(strWhere);
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
private void DataGrid2Bind(int DepID)
{
SqlPager2.RecordCount=bll.GetSubList(DepID).Tables[0].Rows.Count;
// DataSet ds=bll.GetSubList(DepID);
DataSet ds=bll.GetViewSubList(SqlPager1.ItemsPerPage,SqlPager1.CurrentPageIndex+1,"1=1"+strSearch);
Datagrid2.DataSource=ds.Tables[0];
Datagrid2.DataKeyField="DepID";
Datagrid2.DataBind();
}
#endregion


//---------翻页控件事件方法---------------
private void SqlPager1_PageIndexChanged(object sender, Sdtcn.WebControl.PageChangedEventArgs e)
{
DataGrid1Bind();
}

//---------DataGrid项创建绑定的方法-----------------
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//---绑定删除提示框----------------------------
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
{
MessageBox.ShowConfirm((WebControl)(e.Item.Controls[3]),"确定要删除该绿化的记录吗");
}

}

//-------DataGrid各项命令按扭事件方法---------------
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandSource is ImageButton)
{
switch(((ImageButton)e.CommandSource).CommandName)
{

case "Edit":
Server.Transfer("Update.aspx?ContentID="+ DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
break;

case "View":
Server.Transfer("View.aspx?UrlBack=VirescenceList.aspx&ContentID="+ DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
break;

default:
// Do nothing.
break;

}
}
if(e.CommandName=="DeptDetail")
{
DataGrid2Bind(DataGrid1.DataKeyField[e.Item.ItemIndex]);
}

}

//------------查询方法------------
private void Button1_Click(object sender, System.EventArgs e)
{
if (LstSubDept.SelectedValue != "-1")
{
OilTransaction.BLL.Administration.Department bllDept = new OilTransaction.BLL.Administration.Department();
string temp = bllDept.GetChildDeptString(int.Parse(LstSubDept.SelectedValue));
strSearch += " and DepID in (" + temp + ")";
}
if (txtLocus.Text != string.Empty)
strSearch += " and Locus like '%" + txtLocus.Text + "%'";

DataGrid1Bind();
Session["strSearch"] = strSearch;
}
Firestone2003 2006-07-13
  • 打赏
  • 举报
回复
e.Item.ItemIndex这个问题

把事件的完整代码贴出来
diandian82 2006-07-13
  • 打赏
  • 举报
回复
e.Item.ItemIndex是什么东西?跟踪以下
xhy_0423 2006-07-13
  • 打赏
  • 举报
回复
是的,那是什么原因呢?
runrunrun 2006-07-13
  • 打赏
  • 举报
回复
检查一下 e.Item.ItemIndex 的值,多半是-1

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧