<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(条件查询)的更多相关文章

  1. Webform中linq to sql多条件查询(小练习)

    多条件查询:逐条判断,从第一个条件开始判断,如果满足,取出放入集合,再从集合中查询第二个条件... aspx代码: <body> <form id="form1" ...

  2. 动态多条件查询分页以及排序(一)--MVC与Entity Framework版url分页版

    一.前言 多条件查询分页以及排序  每个系统里都会有这个的代码 做好这块 可以大大提高开发效率  所以博主分享下自己的6个版本的 多条件查询分页以及排序 二.目前状况 不论是ado.net 还是EF ...

  3. jqGrid jqGrid分页参数+条件查询

    HTML <div class="row"> <div class="col-sm-20"> <form id="for ...

  4. Rafy 中的 Linq 查询支持(根据聚合子条件查询聚合父)

    为了提高开发者的易用性,Rafy 领域实体框架在很早开始就已经支持使用 Linq 语法来查询实体了.但是只支持了一些简单的.常用的条件查询,支持的力度很有限.特别是遇到对聚合对象的查询时,就不能再使用 ...

  5. Oracle学习总结_day03_day04_条件查询_排序_函数_子查询

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! day03_条件查询_排序_函数 清空回收站: PUR ...

  6. [NHibernate]条件查询Criteria Query

    目录 写在前面 文档与系列文章 条件查询 一个例子 总结 写在前面 上篇文章介绍了HQL查询,我个人觉得使用ORM框架就是为了让少些sql,提高开发效率,而再使用HQL就好像还是使用sql,就觉得有点 ...

  7. PHP-----练习-------租房子-----增删改查,多条件查询

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  8. 【Java EE 学习 17 下】【数据库导出到Excel】【多条件查询方法】

    一.导出到Excel 1.使用DatabaseMetaData分析数据库的数据结构和相关信息. (1)测试得到所有数据库名: private static DataSource ds=DataSour ...

  9. SpringMVC整合Hibernate实现增删改查之按条件查询

    首先我贴出我项目的结构,只完成了条件查询的相关代码,增删改没有写. 1.新建一个动态Web工程,导入相应jar包,编写web.xml配置文件 <context-param> <par ...

随机推荐

  1. python基础——列表

    Python列表脚本操作符 列表对 + 和 * 的操作符与字符串相似.+ 号用于组合列表,* 号用于重复列表. 如下所示: Python 表达式 结果 描述 len([1, 2, 3]) 3 长度 [ ...

  2. python类属性和类方法(类的结构、实例属性、静态方法)

    类属性和类方法 目标 类的结构 类属性和实例属性 类方法和静态方法 01. 类的结构 1.1 术语 —— 实例 使用面相对象开发,第 1 步 是设计 类 使用 类名() 创建对象,创建对象 的动作有两 ...

  3. C++ File Binary

    论操作非文本文件时,std::ios::binary的重要性 今天在读取图片文件的时候,根据图片数据的高宽对图片数据进行读取,但是出现了图片数据读取不完整,但是文件已经到达末尾的情况,中间想过read ...

  4. windows文件服务器的磁盘空间挂载在linux目录下使用

    mount -t cifs //filesystem/serverbackup/SqlBackup/   /data/sqlbackup  -o username=sqlbackup.meizu.co ...

  5. java正则表达式appendReplacement和appendTail方法

    appendReplacement是java中替换相应字符串的一个方法 appendReplacement(StringBuffer sb,String replacement) 将当前匹配子串替换为 ...

  6. Java notepad++ 配置

    1.下载安装插件 NppExec https://nchc.dl.sourceforge.net/project/npp-plugins/NppExec/NppExec%20Plugin%20v0.6 ...

  7. css的性质

    css两个性质: 1.继承性 2.层叠行(选择器的一种选择能力,谁的权重大就选谁) A.选不中,走继承性,(font系列.color.text系列)权重是0 a)有多个父级都设置了这样的样式   走就 ...

  8. SQL注入之Sqli-labs系列第三十四关(基于宽字符逃逸POST注入)和三十五关

    开始挑战第三十四关和第三十五关(Bypass add addslashes) 0x1查看源码 本关是post型的注入漏洞,同样的也是将post过来的内容进行了 ' \ 的处理. if(isset($_ ...

  9. Atom选中多行操作

    没有用过sublime,但是有选取多行的需求 我有一个文本文件,前面几行都是文件夹路径,并且都是单个字母,我想删除路径,保存纯粹的子文件夹名称,这样可以上传谷歌翻译文档,写程序再写txt略显麻烦,直接 ...

  10. PTA寒假二

    7-1 币值转换 (20 分) 输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式.如23108元,转换后变成"贰万叁仟壹百零捌"元.为了简 ...