<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. java集合之List。

    实际上有两种List:一种是基本的ArrayList其优点在于随机访问元素,另一种是更强大的LinkedList它并不是为快速随机访问设计的,而是具有一套更通用的方法. List:次序是List最重要 ...

  2. MFC VC++ 根据文件名获取程序的Pid

    环境:PC Win7 VS VC++ .MFC 使用,输入文件名即可获取程序的pid,进而可以对程序进行操作,比如关闭Porcess等. 头文件: #include <TlHelp32.h> ...

  3. SIMTRACE环境搭建

    搭建simtrace环境 工具环境搭建 仅作参考,具有时效性,请以官方文档为准. 跨平台编译工具arm-elf 参考链接:https://osmocom.org/projects/baseband/w ...

  4. 剑指Offer 41. 和为S的连续正数序列 (其他)

    题目描述 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久,他 ...

  5. box-shadow做出一条线两种颜色

    今天同事问我一个问题,说下图的效果是怎么实现的 我当时想都没有想说这不就是两条线嘛,他说是一条线用box-shadow做出来的,之前也没有遇到过,觉得很有意思就试了一把. 语法 box-shadow: ...

  6. C# 之TripleDESCryptoServiceProvider类加密/解密程序

    这篇博文的编写基于以下博客地址提供的知识: TripleDESCryptoServiceProvider 加密解密 基于该博客,我的毕业设计中密码存储加密字符串这一问题得到解决.

  7. 移动端IOS 固定下方的输入框,点击输入框位置会变的修复

    if(data=="ios"){ var _this = $(".publish"); //无键盘时输入框到浏览器窗口顶部距离 var noInputViewH ...

  8. 安装单机CHD5.12报错解决(补充)

    一.oozie启动失败 (1) 拷贝mysql的驱动文件. 一个是需要把java的mysql的驱动jar文件拷贝到oozie的lib目录中 /opt/cloudera/parcels/CDH-5.12 ...

  9. PTA——乘2后不变

    PTA 7-49 Have Fun with Numbers #include<stdio.h> #include<string.h> #define N 21 int mai ...

  10. 回顾ThreadLocal

    ThreadLocal作为解决特定场景下并发的一种方案,在Spring等框架及面试中经常会被问到,它是Java必须要掌握的基础知识之一. ThreadLocal类的作用是抽象线程内变量的抽象,这类对象 ...