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

Group on field filled in ItemDataBound

3 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 11 Jul 2008, 05:48 AM
Hi all,

In my grid I have a column with DataField = "Topic". Because I'm using a list of objects and the object's topic is retrieved via a method call I use the ItemDataBound event to fill this field.

Now I would like to group by this topic so I do

rgLog.MasterTableView.GroupByExpressions.Add("Topic [Topic] Group By Topic");

This generates an error saying "Field Topic not found in the source table. Please check the expression syntax". This had me puzzled for a few hours. I think the error occurs because it can not find the property "Topic" in my object.

Is this correct?

Is there a way of grouping on a column which gets it's value in the ItemDataBound event?

Without adding the GroupByExpression the grid shows OK, including the "Topic" column.

Thanks,

Vincent.

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 11 Jul 2008, 07:31 AM
Hi Vincent,

In order to group properly, you will need to pass a datasource to the grid which actually contains this column. One such possibility would be to use the NeedDataSource event handler. In this handler, you can call your method, and get all the relevant data. From the data, you construct a DataTable, and pass it as a datasource to the grid. In this way, the group by expression, which relies on the presence of the Column in the DataSource, will function as expected.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Vincent
Top achievements
Rank 1
answered on 13 Jul 2008, 10:52 PM
I am not using a DataTable, instead I use a list of objects. I already use the NeedDataSource event to load my data.

So if I understand correctly, my object NEEDS to have a property TOPIC for this to work?

Is there an event that lets me manipulate the group header maybe?

Thanks,

Vincent.
0
Yavor
Telerik team
answered on 15 Jul 2008, 12:38 PM
Hello Vincent,

Indeed, the object must expose such a property, in order for the grouping to work correctly.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Vincent
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Vincent
Top achievements
Rank 1
Share this question
or