惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
Spread Privacy
Spread Privacy
月光博客
月光博客
L
LINUX DO - 热门话题
C
Cisco Blogs
P
Proofpoint News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
爱范儿
爱范儿
B
Blog
P
Privacy International News Feed
Know Your Adversary
Know Your Adversary
The Cloudflare Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone
J
Java Code Geeks
罗磊的独立博客
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
Simon Willison's Weblog
Simon Willison's Weblog
量子位
H
Help Net Security
The Register - Security
The Register - Security
L
LangChain Blog
GbyAI
GbyAI
Vercel News
Vercel News
S
Schneier on Security
T
Threatpost
T
Threat Research - Cisco Blogs
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
Recorded Future
Recorded Future
G
GRAHAM CLULEY
MyScale Blog
MyScale Blog

博客园 - 马伟

通过xrdp实现远程桌面连接Windows Azure linux虚拟机 使用VNC远程连接Windows Azure Linux虚拟机 设置Windows Azure Linux虚拟机中的root账户 使用Windows Azure PowerShell远程管理Windows Azure虚拟机 将SQL Azure数据库备份到本地SQL Server 2012 asp.net MVC3 “System.Web.Mvc.ModelClientValidationRule”问题 Session的生命周期 在ASP.NET中以编程方式设置母版页 ASP.NET自定义输出缓存提供程序 ASP.NET缓存依赖--自定义缓存依赖 ASP.NET缓存依赖--SQL Server 2005与SQL Server 2008缓存依赖 QueryExtender控件之CustomExpression QueryExtender控件之PropertyExpression QueryExtender控件之RangeExpression QueryExtender控件之SearchExpession <<易学C#>>全书目录 用C#编程合并多个WORD文档 fckeditor编辑器上传文件出现invalid Request问题解决 荣获2009年“微软最有影响力开发者”
QueryExtender控件之OrderByExpression
马伟 · 2010-11-09 · via 博客园 - 马伟

2010-11-09 22:13  马伟  阅读(390)  评论()    收藏  举报

本文部分摘自《ASP.NET4权威指南》

前面我们讲过,QueryExtender 控件支持多种可用于筛选数据的选项。但在使用筛选器选项之后,你还可以使用 OrderByExpression 对象来排序数据。其中,OrderByExpression 类可以按指定列和排序方向对数据进行排序

在使用OrderByExpression时,你可以使用它的DataField 属性指定要排序的数据字段;使用 Direction 属性指定排序方向。OrderByExpression 对象应用到数据源后,你还可以使用 ThenBy 表达式对另一个数据字段执行后续排序。

下面的示例程序演示了如何在ASP.NET4数据库的Employee数据表的Department列中,搜索员工部门等于SearchTextBox文本框中指定的字符串开头的员工信息。其中,OrderByExpression 对象按Workdate数据字段的降序和 EmployeeID字段的升序对数据排序。最后从LinqDataSource 控件返回的结果显示在 GridView 控件中。如代码清单10-6所示:

代码清单10-6OrderByExpressionTest.aspx

代码

<form id="form1" runat="server">
搜索员工部门:
<asp:TextBox ID="SearchTextBox" runat="server" />
<asp:Button ID="Button1" runat="server" Text="搜索" />
<br />
<br />
<asp:LinqDataSource ID="LinqDataSource1" TableName="Employees"
 runat
="server" ContextTypeName="_10_2.EmployeesDataContext"
  EntityTypeName
="" Select="new (employeeid, employeename,
 department, address, email, workdate)">
</asp:LinqDataSource>
<asp:QueryExtender ID="QueryExtender1" runat="server"
 TargetControlID
="LinqDataSource1">
    
<asp:SearchExpression SearchType="StartsWith"
 DataFields
="department">
        
<asp:ControlParameter ControlID="SearchTextBox" />
    
</asp:SearchExpression>
    
<asp:OrderByExpression DataField="workdate" 
Direction
="Descending">
        
<asp:ThenBy DataField="employeeid" 
Direction
="Ascending" />
    
</asp:OrderByExpression>
</asp:QueryExtender>
<asp:GridView ID="GridView1" runat="server" Width="100%"
 DataSourceID
="LinqDataSource1"
 AllowPaging
="True" AutoGenerateColumns="False"
 DataKeyNames
="employeeid">
    
<Columns>
        
<asp:BoundField DataField="employeeid" HeaderText="编号"
 ReadOnly
="True" SortExpression="employeeid" />
        
<asp:BoundField DataField="employeename" HeaderText="姓名"
 SortExpression
="employeename" />
        
<asp:BoundField DataField="department" HeaderText="部门"
 SortExpression
="department" />
        
<asp:BoundField DataField="address" HeaderText="住址"
 SortExpression
="address" />
        
<asp:BoundField DataField="email" HeaderText="邮箱"
 SortExpression
="email" />
        
<asp:BoundField DataField="workdate" HeaderText="工作时间"
 SortExpression
="workdate" />
    
</Columns>
</asp:GridView>
</form

示例运行结果图10-25所示:

10-25:示例运行结果

本文部分摘自《ASP.NET4权威指南》