Search code examples
c#asp.nettelerikradgrid

RadGrid: Advanced Data-binding AND declarative columns?


I am using advanced data binding to filter, sort, and page a Telerik RadGrid. Because the DataSource is set on the NeedDataSource event, the columns and filters are generated based off the structure of the DataSource.

How can I declaratively customize the RadGrid's column filters if I can't access them by a unique ID?

<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    AllowCustomPaging="True"
    AllowFilteringByColumn="True"
    AllowPaging="True"
    AllowSorting="True"
    OnNeedDataSource="RadGrid1_NeedDataSource"
    EnableLinqExpressions="False">
</telerik:RadGrid>

aspx.cs:

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    //RadGrid1Select is a functioning filter/sort/page Select method
    RadGridIsows.DataSource = RadGrid1Select();
    RadGridIsows.VirtualItemCount = count;
}

I am able to customize column filters by putting them directly in the aspx, however this causes there to be a repeat column because the DataSource columns will bind to it anyways. If there is no way to access the RadGrid columns on databinding, is there a way to associate certain columns in the aspx with the DataSource's DataTable when binding?


Solution

  • Creating an association wasn't the issue. If I defined the columns directly in the aspx, then the DataField property already associates to the data. To fix the issue of additional columns getting added, I had to set the RadGrid's AutoGenerateColumns property to false.