码迷,mamicode.com
首页 > 其他好文 > 详细

多条件查询

时间:2015-10-14 15:45:32      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 

using System; using System.Collections.Generic;

using System.Linq; using System.Web;

using System.Web.UI; using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page

{    

protected void Page_Load(object sender, EventArgs e)    

{       //绑定显示数据

  if (!IsPostBack)        

{            

TestDataContext context = new TestDataContext();

            Repeater1.DataSource = context.Car;           

  Repeater1.DataBind();       

  }    

}    

protected void btnSelect_Click(object sender, EventArgs e)   

  {    // 双击查询按钮

    TestDataContext context = new TestDataContext();

        List<Car> list = context.Car.ToList();

        //判断第一个条件      

   string key = txtName.Text;      

   if (key != "")        

{         

    list = list.Where(p=>p.Name.Contains(key)).ToList();

            //使关键字变色          

   foreach (Car data in list)        

     {          

       string s = data.Name.Replace(key, "<mark>" + key + "</mark>");

                data.Name = s;          

   }   

      }

        //判断第二个条件         

       string mi = txtJGmin.Text;   

      string ma = txtJGmax.Text;

        if (mi != "" && ma != "")       

  {        

     decimal min = Convert.ToDecimal(txtJGmin.Text);       

      decimal max = Convert.ToDecimal(txtJGmax.Text);         

    list = list.Where(p=>p.Price.Value>=min && p.Price.Value<=max).ToList();       

  }

        //指定数据源      

   Repeater1.DataSource = list;       

  Repeater1.DataBind();

    }

 

多条件查询

标签:

原文地址:http://www.cnblogs.com/hansonglin/p/4877429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!