SqlDataSource.FilterExpression Property
SqlDataSource.FilterExpression Property
定义
- Assembly:
- System.Web.dll
获取或设置调用 Select(DataSourceSelectArguments) 方法时应用的筛选表达式。
public string FilterExpression { get; set; }
属性值
表示使用 Select(DataSourceSelectArguments) 方法检索数据时应用的筛选表达式的字符串。
异常
已设置 FilterExpression 属性,且 SqlDataSource 处于 DataReader 模式。
示例
下面的代码示例演示如何从 Northwind 数据库中检索数据和筛选使用其FilterExpression字符串和FilterParameters集合。FilterExpression属性应用任何时间Select执行方法以检索数据。 在此示例中,FilterExpression包含一个筛选器参数,它包含在一个占位符FilterParameters集合。 此外,筛选器参数是ControlParameter绑定到的对象SelectedValue属性的DropDownList控件。 因为DropDownList控件具有其AutoPostBack属性设置为true,为所选内容中的任何更改DropDownList控制导致页面发布回服务器的信息和GridView控件重新绑定到数据源使用新的筛选器来控制。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<p>Show all employees with the following title:
<asp:DropDownList
id="DropDownList1"
runat="server"
AutoPostBack="True">
<asp:ListItem Selected="True">Sales Representative</asp:ListItem>
<asp:ListItem>Sales Manager</asp:ListItem>
<asp:ListItem>Vice President, Sales</asp:ListItem>
</asp:DropDownList></p>
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
FilterExpression="Title='{0}'">
<FilterParameters>
<asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
</FilterParameters>
</asp:SqlDataSource>
<p><asp:GridView
id="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">
<columns>
<asp:BoundField Visible="False" DataField="EmployeeID" />
<asp:BoundField HeaderText="First Name" DataField="FirstName" />
<asp:BoundField HeaderText="Last Name" DataField="LastName" />
</columns>
</asp:GridView></p>
</form>
</body>
</html>
注解
FilterExpression属性值是一个格式字符串表达式 (一个字符串,由处理String.Format方法),它使用中的值FilterExpression字符串中包含任何替换参数的集合。 筛选器表达式语法是相同的语法通过接受RowFilter属性,因为对其应用筛选器表达式RowFilter的属性DataView执行返回的对象Select方法。 有关详情,请参阅Expression。
如果您将参数添加到FilterParameters集合中,您还可以包含格式字符串的占位符 (例如,"{0}")中要替换的参数值的表达式。 根据中的参数的索引替换占位符FilterParameters集合。 如果中的对象FilterParameters集合是null,该对象将替换为空字符串。
可以包括在参数FilterExpression属性。 如果参数是字符串或字符类型,将参数括在单引号内。 如果参数的数值类型,则不需要,引号引起来。 FilterParameters集合中包含的参数,其计算结果中找到占位符FilterExpression属性。
SqlDataSource控件支持筛选数据时,才在DataSet模式。
FilterExpression属性委托给FilterExpression的属性SqlDataSourceView与之关联的对象SqlDataSource控件。
适用于
.NET Framework
另请参阅
SqlDataSource.FilterExpression Property的更多相关文章
- 我爬的entityFramework的坑
老师使用的是mysql的数据库,但是我只有sqlserver的数据库,于是就照猫画虎,想连自己的sqlserver,结果一连跳了几个坑: 坑一:appsetting中的字符串连接是后面还有个s, 坑二 ...
- asp.net学习之再论sqlDataSource
原文:asp.net学习之再论sqlDataSource 本节从上一节没有阐述的几个方面,再讨论一下SqlDataSource的用法及注意的事项. 上一节的链接地址如下:http://www. ...
- asp.net学习之SqlDataSource
原文:asp.net学习之SqlDataSource 通过 SqlDataSource 控件,可以使用 Web 服务器控件访问位于关系数据库中的数据.其中可以包括 Microsoft SQL Serv ...
- 探究@property申明对象属性时copy与strong的区别
一.问题来源 一直没有搞清楚NSString.NSArray.NSDictionary--属性描述关键字copy和strong的区别,看别人的项目中属性定义有的用copy,有的用strong.自己在开 ...
- JavaScript特性(attribute)、属性(property)和样式(style)
最近在研读一本巨著<JavaScript忍者秘籍>,里面有一篇文章提到了这3个概念. 书中的源码可以在此下载.我将源码放到了线上,如果不想下载,可以直接访问在线网址,修改页面名就能访问到相 ...
- -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HO 解决办法
最近在使用maven,项目测试的时候出现了这么一个错.-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2 ...
- python property理解
一般情况下我这样使用property: @property def foo(self): return self._foo # 下面的两个decrator由@property创建 @foo.sette ...
- Android动画效果之Property Animation进阶(属性动画)
前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...
- Android动画效果之初识Property Animation(属性动画)
前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...
随机推荐
- Selenium2+python自动化38-显式等待(WebDriverWait)
From: https://www.cnblogs.com/yoyoketang/p/6517477.html 前言: 在脚本中加入太多的sleep后会影响脚本的执行速度,虽然implicitly_w ...
- C++进阶--结构体和类
// 单纯从语言上来说,两者唯一的区别是,默认成员是公有还是私有 // 从使用习惯上 // 小的消极对象,包含公有数据,没有或仅有很少的基本的成员函数 -- 数据容器 struct Person_t ...
- 【SpringMVC】文件上传Expected MultipartHttpServletRequest: is a MultipartResolver错误解决
本文转载自:https://blog.csdn.net/lzgs_4/article/details/50465617 使用SpringMVC实现文件上传时,后台使用了 MultipartFile类, ...
- PAT 甲级 1011 World Cup Betting (20)(20 分)
1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...
- 客户端负载均衡Feign之四:Feign配置
Ribbon配置 在Feign中配置Ribbon非常简单,直接在application.properties中配置即可,如: # 设置连接超时时间 ribbon.ConnectTimeout=500 ...
- psql: could not connect to server: No such file or directory&&PGHOST
由于环境变量 PGHOST配置不当引起的 postgres@pgdb-> psql psql: could not connect to server: No such file or dire ...
- java使用jedis访问CentOS中的redis
pom.xml <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</ ...
- 2-自己动手写HashMap
public class Entry { // 键 private Object key; // 值 private Object value; //构造器 public Entry(Object k ...
- maven入门安装及HelloWorld实现
一.安装maven 1.下载 https://maven.apache.org/download.cgi 官网进行下载 2.安装 2.1 解压 本人在D盘建立一个maven文件夹,然后 ...
- 图像生成-VAE简介
VAE(Variational Autoencoder) 生成式模型 理论: 基于贝叶斯公式.KL散度的推导 1. 自动编码器的一般结构 2. 产生一幅新图像 输入的数据经过神经网络降维到一个编码 ...