如何在绑定时对来自数据库的数据进行排序 [英] How Do I sort data coming from database at the time of binding

查看:76
本文介绍了如何在绑定时对来自数据库的数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:Label CssClass="block" runat="server" ID="lblSectorFrom" 

Text='<%# DataBinder.Eval(Container.DataItem, "(dep_apt_id)") %>'

ToolTip='<%# DataBinder.Eval(Container.DataItem, "(dep_apt_name)") %>' /

>

   <asp:Repeater ID="repSector" runat="server" DataSource='<%# CType(Container.DataItem,System.Data.DataRowView).Row.GetChildRows("Booking_Part_TO_Sector_FK") %>' >
 <ItemTemplate>
   <asp:Label ID="Label6" CssClass="block" Text='<%# String.Format("{0:dd-MMM-yyyy}", DataBinder.Eval(Container.DataItem, "(dep_datetime)"))%>'

 runat="server" meta:resourcekey="Label6ResourceKey" />
 </ItemTemplate>







Deparure date    from    To 
26june 2015      LHR     LAX
26june 2015      LAX     AKL
03july 2015      LAX     LHR
03july 2015      AKL     LAX



根据dep_datetime进行排序

它以不正确的方式排序,因为在数据库中它只是以这种格式顺序存储值但我想要在绑定时对其进行排序。正确的行程应该是


Sorting is happening acc to dep_datetime
It is sorting in incorrect manner because in the database
it is storing values in this format order only but i want to sort it at the time of binding. the correct itineraries should be

LHr-LAX
LAX-AKL

AKL-LAX
LAX-LHR





如果有人知道这将是很好的帮助。



it will be great help if anyone knows about this.

推荐答案

我想最简单的方法是使用 ORDER BY子句从数据库中获取数据时对数据进行排序 [ ^ ]。



其他选项是对已经提取的数据进行排序,但为了做到这一点,我们需要知道数据存储在程序中的结构类型。是在数据表,POCO等等。
I guess the easiest way is to sort the data when fetching it from the database using an ORDER BY clause[^].

Other option is to sort the data already fetched but in order to do that we'd need to know in what kind of structure the data is stored in your program. Is it in data tables, POCO's and so on.


只需数据视图即可。

请看链接:

dataview sort

希望它有所帮助:)
Simply dataview will work.
see the link:
dataview sort
Hope it helps :)


这篇关于如何在绑定时对来自数据库的数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆