I am defining several columns through the RadGrid definition in the aspx file and several columns programatically in the page load event handler. The problem is that the programatically added columns don't work with sorting or filtering. The grid reloads, but the results are not sorted/filtered. If I define the column in the RadGrid definition instead of adding them programatically, they sort and filter correctly.
Columns defined in RadGrid definition:
<Columns>
<telerik:GridBoundColumn DataField="LeadDistributionId" ReadOnly="true" UniqueName="LeadDistributionId" Visible="true" />
<telerik:GridBoundColumn SortExpression="LeadDistributionType" HeaderText="Lead Distribution Type" DataField="LeadDistributionType" HeaderButtonType="TextButton" HeaderStyle-Width="150" ItemStyle-Width="150" FooterStyle-Width="150" />
<telerik:GridBoundColumn SortExpression="ProgramName" HeaderText="Program" DataField="ProgramName" HeaderButtonType="TextButton" />
<telerik:GridBoundColumn DataField="ProgramID" Visible="false" />
<telerik:GridBoundColumn SortExpression="SupplierName" HeaderText="Supplier" DataField="SupplierName" HeaderButtonType="TextButton" />
<telerik:GridBoundColumn DataField="SupplierID" Visible="false" />
<telerik:GridBoundColumn SortExpression="State" HeaderText="State" DataField="State" HeaderButtonType="TextButton" HeaderStyle-Width="150" ItemStyle-Width="150" FooterStyle-Width="150" />
<telerik:GridBoundColumn DataField="StateID" Visible="false" />
</Columns>
Columns defined programatically:
protected void Page_Load(object sender, EventArgs e)
{
// if this is the initial page request
if (!this.IsPostBack)
{
DataTable dtLeadDistributionSummary =
((
DataView)this.sdsLeadDistributionSummary.Select(new DataSourceSelectArguments())).ToTable();
Regex reCallCenterColumn = new Regex(LeadDistributionSummary.CallCenterColumnRegEx);
foreach (DataColumn dataColumn in dtLeadDistributionSummary.Columns)
{
// if this colummn is a call center column
if (reCallCenterColumn.IsMatch(dataColumn.ColumnName))
{
GridBoundColumn gridBoundColumn = new GridBoundColumn();
// when adding columns programatically in Page_Load event, column
// must be added to the columns collection before setting properties
this.RadGrid1.MasterTableView.Columns.Add(gridBoundColumn);
gridBoundColumn.UniqueName = dataColumn.ColumnName;
gridBoundColumn.DataField = dataColumn.ColumnName;
gridBoundColumn.HeaderButtonType =
GridHeaderButtonType.TextButton;
gridBoundColumn.HeaderStyle.Width = 150;
gridBoundColumn.ItemStyle.Width = 150;
gridBoundColumn.FooterStyle.Width = 150;
gridBoundColumn.Groupable =
true;
gridBoundColumn.AllowFiltering =
true;
// remove "CC-" prefix from column name for header text
gridBoundColumn.HeaderText = reCallCenterColumn.Replace(dataColumn.ColumnName,
"$2");
}
}
// hide grouped columns
foreach (GridGroupByExpression gridGroupByExpression in this.RadGrid1.MasterTableView.GroupByExpressions)
{
foreach (GridGroupByField gridGroupByField in gridGroupByExpression.GroupByFields)
{
this.RadGrid1.MasterTableView.GetColumnSafe(gridGroupByField.FieldName).Visible = false;
}
}
#region
expand first level
//// bind grid so items may be expanded below
//this.RadGrid1.Rebind();
//// loop through group headers
//foreach (GridGroupHeaderItem gridGroupHeaderItem in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
//{
// if (gridGroupHeaderItem.GroupIndex.Length == 1)
// {
// // expand the group
// gridGroupHeaderItem.Expanded = true;
// }
// else
// {
// gridGroupHeaderItem.Expanded = false;
// }
// Groups[gridGroupHeaderItem.GroupIndex] = gridGroupHeaderItem.Expanded;
//}
#endregion
expand first level
}
}