hello,
I have two questions about grouping in RadGrid (Q2 2009).
1. Customizing GridGroupHeader
I would like to display an image in the GridGroupHeader based on an boolean field in the SelectFields-Collection.
Instead of the checkbox, there is an image to be displayed. How is that possible?
2. Expand in multi level grouping hierachy
I can expand all groups on grid load by setting the GroupsDefaultExpanded property of the MasterTableView. Is it possible to expand only the topmost level?
Thanks
I have two questions about grouping in RadGrid (Q2 2009).
1. Customizing GridGroupHeader
I would like to display an image in the GridGroupHeader based on an boolean field in the SelectFields-Collection.
Instead of the checkbox, there is an image to be displayed. How is that possible?
2. Expand in multi level grouping hierachy
I can expand all groups on grid load by setting the GroupsDefaultExpanded property of the MasterTableView. Is it possible to expand only the topmost level?
Thanks
7 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 15 Sep 2009, 09:55 AM
Hi Thomas,
2. You may try the following code snippet to expand only the 1st level grouping.
CS:
| foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)) |
| { |
| if (item.GroupIndex == "0") |
| { |
| item.Expanded = true; |
| } |
| } |
Thanks
Shinu
0
Thomas
Top achievements
Rank 1
answered on 15 Sep 2009, 10:58 AM
Hi Shinu,
thank you! It works, but not correct for my use case.
The GroupHeader with the GroupIndex 0 ist the first element in the first level.
But there is more than one element in the first level:
0
0_0
0_1
...
1
1_0
1_1
2
...
Is there any possibility to implement your solution in a flexible way (the number of the elements in the first level is dynamic)?
Thanks
thank you! It works, but not correct for my use case.
The GroupHeader with the GroupIndex 0 ist the first element in the first level.
But there is more than one element in the first level:
0
0_0
0_1
...
1
1_0
1_1
2
...
Is there any possibility to implement your solution in a flexible way (the number of the elements in the first level is dynamic)?
Thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Sep 2009, 12:01 PM
Hi,
I am not sure if there is any other easy way to achieve this. Here is a workaround which worked on my end. I know this is not a neat solution. But any ways you may give it a try ;)
CS:
Regards
Shinu
I am not sure if there is any other easy way to achieve this. Here is a workaround which worked on my end. I know this is not a neat solution. But any ways you may give it a try ;)
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridGroupHeaderItem) |
| { |
| GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; |
| if (!groupHeader.GroupIndex.Contains("_")) |
| { |
| groupHeader.Expanded = true; |
| } |
| } |
| } |
Regards
Shinu
0
Thomas
Top achievements
Rank 1
answered on 15 Sep 2009, 12:16 PM
Hi,
thanks a lot! It´is simple and it works :-)
Do you have some idea about the image in the GroupHeader (item 1 in my first post).
0
Accepted
Shinu
Top achievements
Rank 2
answered on 16 Sep 2009, 04:32 AM
Hi Thomas,
I hope you are trying to add the image in the GridGroupHeader depending upon the boolean value. Here is the sample code. You may modify it accordingly.
ASPX:
CS:
Regards
Shinu
I hope you are trying to add the image in the GridGroupHeader depending upon the boolean value. Here is the sample code. You may modify it accordingly.
ASPX:
| <telerik:GridGroupByExpression> |
| <GroupByFields> |
| <telerik:GridGroupByField FieldAlias="Discontinued" FieldName="Discontinued" FormatString="" |
| HeaderText="" /> |
| </GroupByFields> |
| <SelectFields> |
| <telerik:GridGroupByField FieldAlias="Discontinued" FieldName="Discontinued" FormatString="" |
| HeaderText="" /> |
| </SelectFields> |
| </telerik:GridGroupByExpression> |
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridGroupHeaderItem) |
| { |
| GridGroupHeaderItem Groupheader = (GridGroupHeaderItem)e.Item; |
| ImageButton imgbtn = new ImageButton(); |
| imgbtn.ID = "GroupImage1"; |
| if (Groupheader.DataCell.Text.Contains("True")) |
| { |
| imgbtn.ImageUrl = "~/Image/Edit.gif"; |
| } |
| else |
| imgbtn.ImageUrl = "~/Image/Filter.gif"; |
| Groupheader.Controls[1].Controls.Clear(); |
| Groupheader.Controls[1].Controls.Add(imgbtn); |
| } |
| } |
Regards
Shinu
0
Thomas
Top achievements
Rank 1
answered on 16 Sep 2009, 12:34 PM
hi Shinu,
thanks for your answer. Thats exactly what i need.
There is still one little problem:
When i expand an item in the second level (the level with the image), there is a postback and after the postback
the RadGrid1_ItemDataBound not fires again.
Can i use an another event?
thanks for your answer. Thats exactly what i need.
There is still one little problem:
When i expand an item in the second level (the level with the image), there is a postback and after the postback
the RadGrid1_ItemDataBound not fires again.
Can i use an another event?
0
Thomas
Top achievements
Rank 1
answered on 16 Sep 2009, 02:32 PM
ok its done.
i set the GroupLoadMode to Client. Now it works.
Shinu, many thanks for your help!