I have a gridview that displays a calculated field, based on a db source field it populates with.
can i sort by it? i can't seem to figure out how to do it?
example:
my templatefield looks like this:
<asp:TemplateField HeaderText="Category" SortExpression="category" >
<ItemTemplate>
<asp:Label runat="server" Text='<%# BuildCategory(DataBinder.Eval(Container, "DataItem.category")) %>'
ID="lblPrice"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
where category is party of the datasource, but what gets displayed is a calculated value - which is different from the category.
what can i put in the "SOrtExpression" to make it sort by the new value - taht g开发者_StackOverflow社区ets displayed?
No, you probably want to do this before you assign the datasource. Process the datasource (with your calculated field), and then feed it to your grid.
So your process might look something like:
- Retrieve dataset
- Add/Process Calculated field
- Sort the dataset and bind it to the grid OR first bind the dataset to the grid and then you can use the grid's functions to sort it if supported.
精彩评论