|
沙发
楼主 |
发表于 2012-10-22 07:50:33
|
只看该作者
为了更好使用模板列
我作了以下改动,建议更新到官方源文件里GridRow.cs
/// <summary>
/// 初始化模板容器
/// </summary>
public void InitTemplateContainers()
{
GridColumnCollection columns = _grid.AllColumns;
if (TemplateContainers == null)
{
TemplateContainers = new GridRowControl[columns.Count];
}
//针动动态添加的模板列,要相应增加TemplateContainers的长度
if (TemplateContainers.Length < columns.Count)
{
GridRowControl[] newGridRowControlContainers = new GridRowControl[columns.Count];
for (int i = 0; i < TemplateContainers.Length; i++)
{
newGridRowControlContainers[i] = TemplateContainers[i];
}
TemplateContainers = newGridRowControlContainers;
}
for (int i = 0, count = columns.Count; i < count; i++)
{
GridColumn column = columns;
if (column is TemplateField)
{
if (TemplateContainers[column.ColumnIndex] == null)
{
TemplateField field = column as TemplateField;
GridRowControl control = new GridRowControl(DataItem, RowIndex);
//control.ID = String.Format("{0}_{1}_{2}", Grid.ID, RowIndex, column.ColumnIndex);
control.ID = String.Format("c{0}r{1}", column.ColumnIndex, RowIndex);
field.ItemTemplate.InstantiateIn(control);
Controls.Add(control);
TemplateContainers[column.ColumnIndex] = control;
}
}
}
}
Grid.cs
/// <summary>
/// 处理回发数据
/// </summary>
/// <param name="postDataKey">回发数据键</param>
/// <param name="postCollection">回发数据集</param>
/// <returns>回发数据是否改变</returns>
public override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
//检查并恢复GridRow模板列(包括动态模板列)
foreach (var row in this.Rows)
{
row.InitTemplateContainers();
}
|
|