Smith, Joe
and sort by last name as well.
I have tried a GridTemplateColumn, which gives me the proper display, but I can't sort.
I have tried GridBoundColumn, which gives me the sort functionality, but i have to display the data in two columns.
How can i use GridBoundColumn to display Datafield="Contact.Lastname, Contact.Firstname"?
3 Answers, 1 is accepted
You can have the following RadGrid template column definition to attain the sorting functionality you are after:
<telerik:GridTemplateColumn DataField="LastName" |
SortExpression="LastName" |
HeaderText="Names"> |
<ItemTemplate> |
<asp:Label runat="server" ID="Label1" |
Text='<%#Eval("LastName") + ", " + Eval("FirstName")%>'> |
</asp:Label> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
More information about how to implement sorting for template columns you can find in these resources:
http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/GeneralFeatures/ColumnTypes/DefaultCS.aspx (see the last column in the grid)
http://www.telerik.com/help/aspnet-ajax/grdsortingforhyperlinktemplatecolumns.html
Best regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

<telerik:GridTemplateColumn DataField="Contact.LastName"
SortExpression="Contact.LastName" HeaderText="Name">
<ItemTemplate>
<asp:Label runat="server" ID="Label1"
Text='<%#Eval("Contact.LastName") + ", " + Eval("Contact.FirstName")%>'>
</asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
Again, my other columns sort fine, and if i seperate the two columns and use a GridBoundColumn like this:
<telerik:GridBoundColumn DataField="Contact.LastName" HeaderText="Last Name" ItemStyle-Width="80px" />
<telerik:GridBoundColumn DataField="Contact.Firstname" HeaderText="First Name" ItemStyle-Width="80px" />
I can sort just fine, but my data obviously displays as two columns, Last and First name.
Oddly enough, this workaround works. If I use both the GridBoundColumn and set visable to false, and then display my template column as shown below, i get the functionality I need...but there must be a better way.
<telerik:GridBoundColumn DataField="Contact.LastName" HeaderText="Last Name" ItemStyle-Width="80px" Visible="false" />
<telerik:GridTemplateColumn DataField="Contact.LastName"
SortExpression="Contact.LastName" HeaderText="Name">
<ItemTemplate>
<asp:Label runat="server" ID="Label1"
Text='<%#Eval("Contact.LastName") + ", " + Eval("Contact.FirstName")%>'>
</asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
Unfortunately the GridTemplateColumn won't be able to evaluate nested properties as a sort expression.
The workaround you use - GridBoundColumn with Visible set to false is one possible workaround for this.
All the best,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.