标签:
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