积极答复者
dropdownlist内容作为SQL的查询参数

问题
-
dropdownlist的值作为sqldatasource的查询参数,其中有一项为“全部”,怎样实现当选“全部”时sqldatasource取回全部数据。
- 已移动 肖小勇Moderator 2011年4月16日 3:19 ASP.NET 相关问题 (发件人:.NET Framework 一般性问题讨论区)
答案
全部回复
-
使用数据绑定,为你的查询条件定义个类,如下:
class Argument
{
public string Text{get;set;} //用于显示在Dropdownlist中的文本
public string Value {get;set;} // 用于制定 where 条件值的表达式
}对于 Text 为 "全部"的Argumnet对象,将其 Value 设置为 "1 = 1"
对于 Text 不为"全部"的 Argument对象,将其 Value 设置为 "field = xxxxx";
然后在查询之前,拼接 sql 的 where 条件
select * from table where + argument.value;
-
可以换用object datasource然后在类的选择方法里面加上判断的逻辑
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP