views:

121

answers:

2

Hi I am using a gridview and have have to set a sort expression, I am using:

<asp:TemplateField HeaderText="Order Name" SortExpression="OrderId">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# OrderName(((DataLayer.Car)Container.DataItem).OrderId) %>' />
                </ItemTemplate>
                <ItemStyle Width="120px" />
            </asp:TemplateField>

But I rather want to sort by the name which I get from the OrderId than the actual OrderId - but I havent been able to find out if this is doable, and how?

A: 

You have to use the field name of the data results that you have in your grid. If you have the field in the results, use it.

rball
A: 

If you are ever need to support paging (and you're not storing the entire result set in session or viewstate or something) you will not be able to page through the results sorted by the ordername.

As long as your resultset is small (and you are storing it), you could create a new object that contains the OrderID and OrderName, fill it with the orderid's and ordername's, then bind to that.

The best thing to do would be to have your ordername come from your datasource if possible.

Jimmie R. Houts