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

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Troy Hunt's Blog
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
Cyberwarzone
Cyberwarzone
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
T
Threatpost
H
Heimdal Security Blog
W
WeLiveSecurity
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
IT之家
IT之家
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
TaoSecurity Blog
TaoSecurity Blog
A
About on SuperTechFans
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
量子位
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
Vercel News
Vercel News
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security

博客园 - 马伟

通过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控件之OrderByExpression QueryExtender控件之PropertyExpression QueryExtender控件之RangeExpression QueryExtender控件之SearchExpession <<易学C#>>全书目录 用C#编程合并多个WORD文档 fckeditor编辑器上传文件出现invalid Request问题解决 荣获2009年“微软最有影响力开发者”
QueryExtender控件之CustomExpression
马伟 · 2010-11-09 · via 博客园 - 马伟

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

 

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

如果上面的表达式类都不能够满足你的要求,那么你可以通过CustomExpression类来提供可用于QueryExtender控件中的自定义 LINQ 表达式。CustomExpression 类使你能够在应用程序中指定自定义表达式,然后在事件处理程序中调用它。

下面的示例演示了如何创建一个由 QueryExtender 控件使用的 CustomExpression 对象。其中,该自定义表达式调用包含自定义 LINQ 表达式的 QueryEmployees方法。筛选操作的结果显示在 GridView 控件中。如代码清单10-7所示:

代码清单10-7CustomExpressionTest.aspx

代码

<form id="form1" runat="server">
<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:CustomExpression OnQuerying="QueryEmployees">
    
</asp:CustomExpression>
</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>

  在上面的代码中,通过CustomExpression对象的OnQuerying属性指定了自定义 LINQ 表达式的 QueryEmployees方法。其中,后台的自定义 LINQ 查询的事件处理程序QueryEmployees代码如下所示:

在上面的代码中,通过CustomExpression对象的OnQuerying属性指定了自定义 LINQ 表达式的 QueryEmployees方法。其中,后台的自定义 LINQ 查询的事件处理程序QueryEmployees代码如下所示:

代码

protected void QueryEmployees(object sender,
 CustomExpressionEventArgs e)
{
    e.Query 
= from p in e.Query.Cast<Employee>()
                
where p.employeeid >= 5
                select p;

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

10-26:示例运行结果

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