I have a DataColumn which contains an item ID and TemplateColumn for that DataColumn, which displays item name depending on ID it's bound to. When I press a header to sort grid, items should sort by names, not by ids. How can I do that?
Almost forgot. Everything I have is a ready-to-use dataset, I cannot manipulate SQL statements and I don't have item names included in that dataset.
Thank you.
11 Answers, 1 is accepted

<
telerik:GridTemplateColumn
DataField
=
"Name"
HeaderText
=
"Name"
UniqueName
=
"Name"
>
<
ItemTemplate
>
<%# Eval("ID") %>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
// in this sample it shows ID but short by Name.
If above code is not help you then check below link and check
GridTemplateColumn
in this.http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
let me know if any concern.
if this is not your case then elaborate your case.
Thanks,
Jayesh Goyani

void label_DataBinding(object sender, EventArgs e) {
Label lbl = (Label)sender; GridDataItem dataItem = lbl.NamingContainer as GridDataItem; DataRowView drv = (DataRowView)dataItem.DataItem; if (_refItems.ContainsKey(drv[Item.user_name].ToGuid())) { lbl.Text = _refItems[drv[Item.user_name].ToGuid()].Caption; } }And I cannot set SortExpression to "Name" because there's no column "Name" in the dataset.

Anyone can help?
As Jayesh demonstrated, the DataField of your GridTemplateColumn is used for sorting. Alternatively, you can set the SortExpression property if you want to sort by a different data field. In any case, you need to have a column in your DataSet corresponding to the specified field name. RadGrid can only sort by columns in tabular data or by properties in lists of objects. What is your particular scenario? You said you do not have a "Name" column in your data set. What data do you need to sort by?
Greetings,
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Thank you for reply.
There is a code block which I posted above. Column contains an ID, and in DataBinding event template refers to dictionary which contains an item with this ID, and it sets label text to that name. I cannot use regular combobox column because reference data we use is hierarchycal and should be displayed as TreeView in popup window. So we have a column which contains ID and displays Name, and this column should be sorted by Name. That was why I asked if there is a custom sorting for template columns.
One option you can take is to use custom sorting in this case. Custom sorting is implemented by handling RadGrid's SortCommand event. You check the command parameters and, if you identify your Name column is to be sorted, cancel the built-in sorting by setting e.Canceled = true. Then you need to sort your data programmatically for this column. I have created a test page to demonstrate this case. The code includes comments to guide you through the logic. Let me know how this works for you.
Greetings,
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Looks like this is going to work with my project but I cannot implement it fully because I don't have NeedDataSource event ever fired. I create grid entirely in code-behind and it fully consists of template columns. I'm trying to be a good boy building it in Page_Init and calling DataBind() only when !IsPostBack. SortCommand event fires correctly and calls Rebind() after all sorting stuff as in your sample but NeedDataSource still won't fire.
What else this all could be about?
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

And 1 more question. How do I draw a triangle in header template? Well actually I know how and where to draw but how do I access SortExpression and SortOrder from header template?
Thank you.
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
