如何在GridView中显示符合条件的数据 急!急!急! 在DropDownList中选择查询条件,然后单击查询按钮,在GridView中显示符合条件的数据。注:我用的是VS2008+SQL2005,连接数据库的方法是 LINQ to SQL 类,不需要写连接数据库语句的那种 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LINQ语法不会,给LZ个思路,根据选择的内容拼接条件查询,重新绑定数据即可 var retProducts=from p in dataContext.Products where p.Price>10 select p;gv.DataSource=retProducts;gv.DataBind(); var p= from c in ctx.Userwhere c.Country == "" select p;db.ExecuteCommand(""); protected DataClasses1DataContext dc; protected BindingSource bind; private void 下载绑定数据按钮_Click(object sender, TreeNodeMouseClickEventArgs e) { //表的名字是zidian,有个字段leibie dc = new DataClasses1DataContext(); var WAF_pihao = from a in dc.zidian where a.leibie == “xxx" select a; bind = new BindingSource();//看你是否需要 bind.DataSource = WAF_pihao;//看你是否需要 bindingNavigator1.BindingSource = bind;//看你是否需要 dataGridView1.DataSource = bind; this.dataGridView1.Columns[1].HeaderText = " 备 注";//看你是否需要 this.dataGridView1.Columns[2].Visible = false;//看你是否需要 }===========================如果你有使用protected BindingSource bind; bind = new BindingSource();//看你是否需要 bind.DataSource = WAF_pihao;//看你是否需要 bindingNavigator1.BindingSource = bind;//看你是否需要的话,你可以在按钮中用 ,bind.MoveNext;跳下一记录 ,bind.AddingNew增加新记录等等编辑功能 来个最简单版本,看不懂的话protected DataClasses1DataContext dc; private void 下载绑定数据按钮_Click(object sender, TreeNodeMouseClickEventArgs e) { //表的名字是zidian,有个字段leibie dc = new DataClasses1DataContext(); dataGridView1.DataSource = from a in dc.zidian where a.leibie == “xxx" select a; }where a. 后面是条件,你自己改下就成了 this.dataGridView1.GridColor = Color.Brown; string MySQL = "select * from rooms Where [distinct]='" + this.comboBox1.Text+ " ' "; DataTable MyTable = new DataTable(); SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, db1.sqlConnection1); MyAdapter.Fill(MyTable); this.dataGridView1.DataSource = MyTable; MyAdapter.Dispose(); 新人求助 。c#调用 c++写的dll。高手指教啊 windows mobile中 制作数字键盘 如何捕获指定进程开始运行?(不使用Timer) 请问如何当一个窗体dispose的时候触发本窗体中的所有控件的validating事件 C#中如果在ListView中实现拖放? ★★C#菜鸟级问题,大家来帮忙啊★★ 请问如何在C#中执行一个.BAT的批处理文件? 谁用C#做过视频监控系统啊 由C#风潮想起的-给初学编程者的忠告 一个准备学习C#.net的菜鸟。 linq toList 结果要怎么引用? winform中Excel导入Access,如何导入中文标头..大侠请进
gv.DataSource=retProducts;
gv.DataBind();
where c.Country == ""
select p;
db.ExecuteCommand("");
protected BindingSource bind;
private void 下载绑定数据按钮_Click(object sender, TreeNodeMouseClickEventArgs e)
{
//表的名字是zidian,有个字段leibie
dc = new DataClasses1DataContext();
var WAF_pihao = from a in dc.zidian
where a.leibie == “xxx"
select a;
bind = new BindingSource();//看你是否需要
bind.DataSource = WAF_pihao;//看你是否需要
bindingNavigator1.BindingSource = bind;//看你是否需要
dataGridView1.DataSource = bind;
this.dataGridView1.Columns[1].HeaderText = " 备 注";//看你是否需要
this.dataGridView1.Columns[2].Visible = false;//看你是否需要
}
===========================
如果你有使用protected BindingSource bind;
bind = new BindingSource();//看你是否需要
bind.DataSource = WAF_pihao;//看你是否需要
bindingNavigator1.BindingSource = bind;//看你是否需要
的话,你可以在按钮中用 ,bind.MoveNext;跳下一记录 ,bind.AddingNew增加新记录等等编辑功能
protected DataClasses1DataContext dc;
private void 下载绑定数据按钮_Click(object sender, TreeNodeMouseClickEventArgs e)
{
//表的名字是zidian,有个字段leibie
dc = new DataClasses1DataContext();
dataGridView1.DataSource = from a in dc.zidian where a.leibie == “xxx" select a;
}
where a. 后面是条件,你自己改下就成了
DataTable MyTable = new DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, db1.sqlConnection1);
MyAdapter.Fill(MyTable);
this.dataGridView1.DataSource = MyTable;
MyAdapter.Dispose();