程序在用到几个小时后突然出现如下错误,重启服务器后又好拉,请问何故??
Index was outside the bounds of the array. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
[IndexOutOfRangeException: Index was outside the bounds of the array.]
   Ydyd.WebControls.RelatedList.RelatedListItemsFromDataSet.GenerateXmlData(StringBuilder xmlData, String parentValue)
   Ydyd.WebControls.RelatedList.RelatedListItemsFromDataSet.GenerateXmlData(StringBuilder xmlData, String parentValue)
   Ydyd.WebControls.RelatedList.RelatedListItemsFromDataSet.GenerateXmlData(StringBuilder xmlData, String parentValue)
   Ydyd.WebControls.RelatedList.RelatedListItemsFromDataSet.GenerateXmlData(StringBuilder xmlData, String parentValue)
   Ydyd.WebControls.RelatedList.RelatedListItemsFromDataSet.GenerateXmlData(StringBuilder xmlData, String parentValue)
   Ydyd.WebControls.RelatedList.RelatedListItemsFromDataSet.GetClientXmlData(String controlID, Page page)
   Ydyd.WebControls.RelatedList.RelatedList.InitItems()
   Ydyd.WebControls.RelatedList.RelatedList.OnDataBinding(EventArgs e)
   Ydyd.WebControls.RelatedList.RelatedList.DataBind()
   WebAppPowerDataGridTest.sanjishu.BindRelatedList() in D:\sanjishu.aspx.cs:101
   WebAppPowerDataGridTest.sanjishu.Page_Load(Object sender, EventArgs e) in D:\sanjishu.aspx.cs:39
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731
---------------------------------------------------------------------------------
private void BindRelatedList()//装载所有列表
{

string con = data.constr,sql="";
SqlConnection connection = new SqlConnection(con);
sql="select * from category";
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
da.Fill(ds);

            
ArrayList b = new ArrayList();
b.Add("DropDownList5");
b.Add("DropDownList6");
b.Add("DropDownList7");
b.Add("DropDownList4"); RelatedList2.DataSource = ds;
RelatedList2.ListID = b;
RelatedList2.DataBind();
}

解决方案 »

  1.   

    是不是页面刷新没有判断,导致每刷新一次就绑定一回list
      

  2.   

    应该不是,我这样判断的private void Page_Load(object sender, System.EventArgs e)
    {
    if (!Page.IsPostBack)
    {   

    BindRelatedList();

    }
                       }
      

  3.   

    if (!Page.IsPostBack)
    {   

    BindRelatedList();

    }
    BindRelatedList();只在页面载入时执行了一遍
      

  4.   

    你可以在page_load时只载入一次,但你要在修改那个list的事件完成后重新绑定一下