Webform(条件查询)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
名称:<asp:TextBox ID="name" runat="server"></asp:TextBox>
油耗:<asp:DropDownList ID="oil" runat="server">
<asp:ListItem Text="大于" Value=">"></asp:ListItem>
<asp:ListItem Text="小于" Value="<"></asp:ListItem>
<asp:ListItem Text="等于" Value="="></asp:ListItem>
<asp:ListItem Text="大于等于" Value=">="></asp:ListItem>
<asp:ListItem Text="小于等于" Value="<="></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="oiltext" runat="server"></asp:TextBox>
价格:<asp:DropDownList ID="price" runat="server">
<asp:ListItem Text="20万至30万" Value="price>=20 and price<=30"></asp:ListItem>
<asp:ListItem Text="30万至40万" Value="price>=30 and price<=40"></asp:ListItem>
<asp:ListItem Text="大于40万" Value="price>=40"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="查询" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<table style="width: 100%; background-color: blue; text-align: center;">
<tr style="color: white;">
<td>编号</td>
<td>名称</td>
<td>油耗</td>
<td>马力</td>
<td>排量</td>
<td>价格</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr style="background-color: white;">
<td><%#Eval("Ids") %></td>
<td><%#Eval("Name") %></td>
<td><%#Eval("Oil") %></td>
<td><%#Eval("Powers") %></td>
<td><%#Eval("Exhaust") %></td>
<td><%#Eval("Price") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table> </form>
</body>
</html>
条件查询.aspx
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = new CarData().SelectAll();
Repeater1.DataBind();
}
Button1.Click += Button1_Click;
} void Button1_Click(object sender, EventArgs e)
{
int count = ;
string tsql = "select*from Car";
Hashtable hs = new Hashtable();
if (name.Text.Length > )
{
tsql += " where name like @a";
hs.Add("@a", "%" + name.Text.Trim() + "%");
count++;
}
if (oiltext.Text.Length > )
{
if (count > )
{
tsql += " and oil "+oil.SelectedValue +"@b";
}
else
{
tsql += " where oil " + oil.SelectedValue + "@b";
}
hs.Add("@b", oiltext.Text.Trim());
count++;
}
if (price.SelectedValue != null)
{
if (count > )
{
tsql += " and " + price.SelectedValue;
}
else
{
tsql += " where " + price.SelectedValue;
} count++;
} Repeater1.DataSource = new CarData().SelectAll(tsql,hs);
Repeater1.DataBind();
}
}
条件查询.cs
Webform(条件查询)的更多相关文章
- Webform中linq to sql多条件查询(小练习)
多条件查询:逐条判断,从第一个条件开始判断,如果满足,取出放入集合,再从集合中查询第二个条件... aspx代码: <body> <form id="form1" ...
- 动态多条件查询分页以及排序(一)--MVC与Entity Framework版url分页版
一.前言 多条件查询分页以及排序 每个系统里都会有这个的代码 做好这块 可以大大提高开发效率 所以博主分享下自己的6个版本的 多条件查询分页以及排序 二.目前状况 不论是ado.net 还是EF ...
- jqGrid jqGrid分页参数+条件查询
HTML <div class="row"> <div class="col-sm-20"> <form id="for ...
- Rafy 中的 Linq 查询支持(根据聚合子条件查询聚合父)
为了提高开发者的易用性,Rafy 领域实体框架在很早开始就已经支持使用 Linq 语法来查询实体了.但是只支持了一些简单的.常用的条件查询,支持的力度很有限.特别是遇到对聚合对象的查询时,就不能再使用 ...
- Oracle学习总结_day03_day04_条件查询_排序_函数_子查询
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! day03_条件查询_排序_函数 清空回收站: PUR ...
- [NHibernate]条件查询Criteria Query
目录 写在前面 文档与系列文章 条件查询 一个例子 总结 写在前面 上篇文章介绍了HQL查询,我个人觉得使用ORM框架就是为了让少些sql,提高开发效率,而再使用HQL就好像还是使用sql,就觉得有点 ...
- PHP-----练习-------租房子-----增删改查,多条件查询
练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...
- 【Java EE 学习 17 下】【数据库导出到Excel】【多条件查询方法】
一.导出到Excel 1.使用DatabaseMetaData分析数据库的数据结构和相关信息. (1)测试得到所有数据库名: private static DataSource ds=DataSour ...
- SpringMVC整合Hibernate实现增删改查之按条件查询
首先我贴出我项目的结构,只完成了条件查询的相关代码,增删改没有写. 1.新建一个动态Web工程,导入相应jar包,编写web.xml配置文件 <context-param> <par ...
随机推荐
- linux下使用命令修改IP地址
使用root用户登录进入Linux,打开进去终端 在终端中输入:vi /etc/sysconfig/network-scripts/ifcfg-eth0 (最后的eth0是网卡名,我的是Auto_et ...
- Hadoop & Spark
Hadoop & Spark 概述 Apache Hadoop 是一种通过服务集群并使用MapReduce编程数据模型完成大数据的分布式处理框架,核心模块包括:MapReduce,Hadoop ...
- 成功解决android studio打包报错
Win7系统,Android Studio 版本2.3.1,对cpp-empty-test使用了 cocos compile -p android --android-studio,命令 编译打包AP ...
- python的format格式化
使用方法: '{}bbccc'.format(aa) = aabbcc, 用来代替python2中的%,即替换. 1.通过位置来指定替换 In [2]: '{0},{1}'.format('a', ...
- 使用Sublime Text 3进行Markdown 编辑+实时预览
这种做法可能会对你的磁盘IO造成一小部分性能负担,但负面影响足以忽略. 另外,由于这种频率的读写会被磁盘缓存接管,不必担心磁盘寿命的影响. 对于刚安装好的Sublime Text,我们需要安装一个软件 ...
- httpd does not appear to be running and proxying cobbler, or SELinux is in the way.
当我们执行cobbler check时,出现这种错误:httpd does not appear to be running and proxying cobbler, or SELinux is i ...
- SpringMVC + MyBatis分库分表方案
mybatis作为流行的ORM框架,项目实际使用过程中可能会遇到分库分表的场景.mybatis在分表,甚至是同主机下的分库都可以说是完美支持的,只需要将表名或者库名作为动态参数组装sql就能够完成.但 ...
- oc语言的Foundation框架(学习笔记1)
Foundation框架 1.Foundation框架介绍 框架是由许多类.方法.函数以及文档按照一定的规则组合的起来的集合. cocoa程序编写主要用到2个框架Foundation和Applicat ...
- Jquery仿百度经验左右滚动切换效果(转)
http://www.xwcms.net/webAnnexImages/fileAnnex/201608/61342/index.html
- 深入学习Motan系列(三)——服务发布
袋鼠回头看了看文章,有些啰嗦,争取语音简练,不断提高表达力!袋鼠奋起直追! 注:此篇文章,暂时为了以后时间线排序的需要,暂时发表出来,可是仍然有许多地方需要改写.自己打算把服务端发布,客户端订阅都搞定 ...