protected virtual void CreateControlHierarchy(bool useDataSource)
{
IEnumerable data = null;
int dataItemCount = -1;
if (this.itemsArray != null)
{
this.itemsArray.Clear();
}
else
{
this.itemsArray = new ArrayList();
}
if (!useDataSource)
{
dataItemCount = (int) this.ViewState["_!ItemCount"];
if (dataItemCount != -1)
{
data = new DummyDataSource(dataItemCount);
this.itemsArray.Capacity = dataItemCount;
}
}
else
{
data = this.GetData();
ICollection is2 = data as ICollection;
if (is2 != null)
{
this.itemsArray.Capacity = is2.Count;
}
}
if (data != null)
{
int itemIndex = 0;
bool flag = this.separatorTemplate != null;//是否有分隔符模版
dataItemCount = 0;
if (this.headerTemplate != null)
{
this.CreateItem(-1, ListItemType.Header, useDataSource, null);
}
foreach (object obj2 in data)
{
if (flag && (dataItemCount > 0))
{
this.CreateItem(itemIndex - 1, ListItemType.Separator, useDataSource, null);
}
ListItemType itemType = ((itemIndex % 2) == 0) ? ListItemType.Item : ListItemType.AlternatingItem;
RepeaterItem item = this.CreateItem(itemIndex, itemType, useDataSource, obj2);//Item和Alter交替创建
this.itemsArray.Add(item);
dataItemCount++;
itemIndex++;
}
if (this.footerTemplate != null)
{
this.CreateItem(-1, ListItemType.Footer, useDataSource, null);//创建底部
}
}
if (useDataSource)
{
this.ViewState["_!ItemCount"] = (data != null) ? dataItemCount : -1;//给ViewState的ItemCount赋值
}
}
能不能给我详细解释一下上面代码的意思?
哪句你看不懂???比如CreateItem这个方法,你就看看他定义的参数啊,慢慢来嘛