This is a migrated thread and some comments may be shown as answers.

RadGrid - Reuse for different datasets; and have filters showing data.

1 Answer 40 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 19 Apr 2017, 10:12 PM

(If this is the wrong section to post into, please advise and I'll repost in the proper spot.)

So I need some assistance as I have an idea of what I need, but putting it into code is the challenge. (Or pseudo code).

a) Can't I utilize the RadGrid object with different datasets depending on the 'dropdown box' selections?

b) Can't I bind the data, dynamically display headers, AND, have the dataset fields data grouped into filters?

 

I'm challenged, that I need different RadGrids for different datasets.

(Read between the lines, my engineer is saying it's difficult; but my experience with Telerik isn't noob, thus it doesn't sound difficult.)

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 24 Apr 2017, 01:41 PM

Hello Jeremy,

You can bind RadGrid to a collection that contains the desired fields and it can generate the necessary columns based on the field types. This is controlled via the AutoGenerateColumns property on the main tag.

Here is a basic example:

<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="true" AllowFilteringByColumn="true" AllowSorting="true" AllowPaging="true" PageSize="3" OnNeedDataSource="RadGrid1_NeedDataSource"></telerik:RadGrid>

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = GetDataWithTypes();
}
 
    protected DataTable GetDataWithTypes()
{
    DataTable dt = new DataTable();
 
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("Details", typeof(string));
    dt.Columns.Add("SomeDate", typeof(DateTime));
 
    dt.Rows.Add(1, "one", new DateTime(2011, 06, 12));
    dt.Rows.Add(2, "two", new DateTime(2011, 12, 12));
    dt.Rows.Add(3, "three", new DateTime(2012, 06, 17));
    dt.Rows.Add(4, "four", new DateTime(2012, 09, 18));
    dt.Rows.Add(5, "five", new DateTime(2013, 03, 18));
 
    return dt;
}

This is read-only for the sake of clarity, yet you can easily use a declarative data source and define your operations there: http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/automatic-crud-operations/defaultcs.aspx. Thus, you can use a dropdown or other UI to configure the data source and/or grid (e.g., you could have several data source controls defined and only switch the DataSourceID).

Of course, you can use your own data access layer manually via the grid events: http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/manual-crud-operations/defaultcs.aspx.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or