Where can I create this object in the asp.net lifecycle methods without receiving an out of range exception. Right now the only place that I can actually get a resource collection containing values is in onreasourcefetched method for webschedule info. But I need to do this before webscheduleinfo is created and it's views are populated with users.
我在哪里可以在asp.net生命周期方法中创建此对象,而不会收到超出范围的异常。现在,我实际上可以获得包含值的资源集合的唯一地方是用于webschedule信息的onreasourcefetched方法。但是我需要在创建webscheduleinfo之前执行此操作,并且用户填充其视图。
protected void Page_Init(object sender, EventArgs e)
{
ResourcesCollection resources = WebScheduleInfo1.VisibleResources;
int count = resources.Count;
Resource obje = (Resource)resources.GetItem(1);
string name = obje.Name;
resources.Clear();
resources.Add(obje);
this.WebScheduleInfo1.ActiveResourceName = name;
}
1 个解决方案
#1
2
You are getting a count of resources but you are not checking to make sure that count is greater than 0.
您获得了一些资源,但您没有检查以确保计数大于0。
(Resource)resources.GetItem(1)
will fail unless the resources collection has at least 2 items in it.
(资源)resources.GetItem(1)将失败,除非资源集合中至少有2个项目。
The collection is 0 based, so if you want the first item do something like this:
该集合基于0,所以如果你想要第一个项目做这样的事情:
protected void Page_Init(object sender, EventArgs e)
{
ResourcesCollection resources = WebScheduleInfo1.VisibleResources;
int count = resources.Count;
if( count > 0 )
{
Resource obje = (Resource)resources.GetItem(0);
string name = obje.Name;
resources.Clear();
resources.Add(obje);
this.WebScheduleInfo1.ActiveResourceName = name;
}
}
#1
2
You are getting a count of resources but you are not checking to make sure that count is greater than 0.
您获得了一些资源,但您没有检查以确保计数大于0。
(Resource)resources.GetItem(1)
will fail unless the resources collection has at least 2 items in it.
(资源)resources.GetItem(1)将失败,除非资源集合中至少有2个项目。
The collection is 0 based, so if you want the first item do something like this:
该集合基于0,所以如果你想要第一个项目做这样的事情:
protected void Page_Init(object sender, EventArgs e)
{
ResourcesCollection resources = WebScheduleInfo1.VisibleResources;
int count = resources.Count;
if( count > 0 )
{
Resource obje = (Resource)resources.GetItem(0);
string name = obje.Name;
resources.Clear();
resources.Add(obje);
this.WebScheduleInfo1.ActiveResourceName = name;
}
}