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

Custom binding a cell value upon row creation

1 Answer 14 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tayyab
Top achievements
Rank 1
Tayyab asked on 18 Oct 2013, 12:31 AM
I'm binding a RadGrid using a custom LINQ query in the NeedDataSource method in the .cs file.  However, there are two columns that I don't want to bind from that datasource, but instead from another List<int> of values called MemberIDs.

The MemberID would affect the left-most column, which either contains a link button that says "Match", or, different link button that would say "Expand".  The "Match" link button should only be displayed if there does not exist a corresponding value in the List<int> MemberIDs for that row's databound record's own MemberID field, otherwise it should display the "Expand" link button which when clicked would open a child RadGrid.

I would like to either be able to raise an event upon the cell creation of that column for that row, and set the appropriate link button in that event's method, or do it in the NeedDataSource event of the RadGrid.  I'm not sure which would work or be better.  Is it possible to have such an event upon cell creation, and be able to check that row's databound record's MemberID keyfield from that event?  If so, what's the name for such an event?

The second thing I need to figure out is that in the expand/collapse column of the RadGrid, I want the angle bracket '<' for expanding a child RadGrid to appear and be clickable, only when the condition for displaying the "Expand" link button (described above) is matched, but if the condition for the "Match" link button is met, then I either don't want to display the angle bracket '<' or make it not be clickable.

Is there a good way to set this up?

Also, is it possible for the "Expand" link button to raise the same event as the angle bracket '>' expand button, i.e., 'e.CommandName == "ExpandCollapse"'?

Thanks for any help possible!

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 22 Oct 2013, 02:25 PM
Hi Tayyab,

Since the text of the link button will depend on the data I would recommend subscribing to the OnItemDataBound event. The idea is to include a template column with a link button which text can be changed in the mentioned event. This button can have an assigned ExpandCollapse command in order for the hierarchy to work. If however the button should not expand the grid records such a command name should not be set and only it's text should be modified. As for checking the MemberID value you can set this field as a DataKeyName and extract it's value from the GridDataItem using the GetDataKeyValue method.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Tayyab
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or