如何在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#问题 intptr c#快捷键小问题 菜鸟提问:图片展示系统(单机版) 正由另一进程使用,因此该进程无法访问该文件 js脚本不能加载,急 再问 C#中怎样使 Web窗体控件的TextBox控件在输入完内容时按回车跳至一个焦点? 点击MessageBox中的确定按键,怎样触发事件 小弟求助,如何在流还没有接收结束的情况下提前拿到部分数据? C#项目求助!请帮忙,在线等 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();