AutoGenerateBands和AutoGenerateColumns应设置为false。另外,我不知道您是否使用GridView来配置网格,尽管我想让您知道WebHierarchicalDataGrid.Columns集合与在设计时间或标记中定义的列的根带相关。至于自动生成的列,可以从WebHierarchicalDataGrid.GridView.Columns访问。
据我了解,您正在从Page_Load事件创建列,请尝试在WHDG_Init上执行此操作。我只是好奇会是什么结果。
protected void WebHierarchicalDataGrid1_Init(object sender, EventArgs e)
{
WebHierarchicalDataGrid1.DataSource = new TestData().GetData();
WebHierarchicalDataGrid1.DataKeyFields = "ID";
WebHierarchicalDataGrid1.Columns.Add(CreateNewBoundDataField("ID", "ID"));
WebHierarchicalDataGrid1.Columns.Add(CreateNewBoundDataField("Name", "Name"));
WebHierarchicalDataGrid1.Bands.Add(CreateNewBand("ChildBand_0", "Child", "ChildID"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("ChildID", "ChildID"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("ID", "ID"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("Address", "Address"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Behaviors.CreateBehavior<Filtering>();
}
public static BoundDataField CreateNewBoundDataField(string columnName, string headerText)
{
BoundDataField boundDataField = new BoundDataField();
boundDataField.DataFieldName = columnName;
boundDataField.Key = columnName;
boundDataField.Header.Text = headerText;
return boundDataField;
}
public static Band CreateNewBand(string key, string dataMember, string dataKeyField)
{
Band band = new Band();
band.AutoGenerateColumns = false;
band.Key = key;
band.DataMember = dataMember;
band.DataKeyFields = dataKeyField;
return band;
}