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

[Solved] dynamic create multiple grids

2 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 18 Aug 2009, 02:07 PM
I have a project need dynamic create multiple grids based on a value in collection object. I need use Grid_NeedDataSource to bind grid. In Grid_NeedDataSource event I call a method BindGrid(). In OnInit event I have following code:

protected override void OnInit(EventArgs e)
{
Collection categories = GetCategories();
foreach (String category in categories)
{
  DefindGridStructure(category);
}
}

The method DefindGridStructure(category) will create a datagrid based on category value. 

void rgGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        BindGrid(CategoryKey);
    }

My question is how can I get Category value in rgGrid_NeedDataSource event. I can't use viewstate value since it will be always the last value of the collection. 

2 Answers, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 26 Aug 2009, 02:01 PM
nobody helps me out? I am still waiting for a solution. Thanks in advance.
0
Veli
Telerik team
answered on 31 Aug 2009, 05:26 AM
Hi Anthony,

You need to save the category value somewhere that will be available in RadGrid's NeedDataSource event. An option would be to save it in the ViewState or Session objects with a unique key for every RadGrid, so that you  have N keys for N categories. Another option would be to somehow include the category value in RadGrid's ID, so that in RadGrid's NeedDataSource event, your (source as RadGrid).ID has the category key included.

Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Anthony
Top achievements
Rank 1
Answers by
Anthony
Top achievements
Rank 1
Veli
Telerik team
Share this question
or