用拼写查询SQl语句的方法。
1。适配器的SelectCommand语句生成数据集dataSet1,与datagrid绑定。
查询时,根据checkbox被选中的情况,动态生成SelectCommand.text。
例:
string str="Select * from cateoty,report where cateory.cd_cateory=report.cd_cateory";
if(checkBox1.checked) str+=" and cateoty.title="+textbox1.text;
if(checkBox2.checked) str+=" and cateoty.name ="+textbox2.text;
if(checkBox1.checked) str+=" and cateoty.key ="+textbox3.text;
atp_search.SelectCommand.Text=str;
atp_search.SelectCommand.fill(dataSet1);
datagrid1.DataBind();2.设置datagrid的selectIndexChange事件。
在事件函数里处理传递参数给另一页
1。适配器的SelectCommand语句生成数据集dataSet1,与datagrid绑定。
查询时,根据checkbox被选中的情况,动态生成SelectCommand.text。
例:
string str="Select * from cateoty,report where cateory.cd_cateory=report.cd_cateory";
if(checkBox1.checked) str+=" and cateoty.title="+textbox1.text;
if(checkBox2.checked) str+=" and cateoty.name ="+textbox2.text;
if(checkBox1.checked) str+=" and cateoty.key ="+textbox3.text;
atp_search.SelectCommand.Text=str;
atp_search.SelectCommand.fill(dataSet1);
datagrid1.DataBind();2.设置datagrid的selectIndexChange事件。
在事件函数里处理传递参数给另一页
解决方案 »
- wince 编写时钟代码 秒针不准问题
- 如何在保存对话框中默认文件类型
- 本人学C#,有很多问题想马上解决,所以想问一下,哪里有C#的QQ论坛啊 ?
- xml语句读取 并添加到treeview上
- 求SQL中用递归....
- 在线等消息!~~图片取地址值是怎么做到的!~请赐教!~
- [急][请高手指点]应用程序产生一个无法处理的异常:进程ID=0xb78(2936)线程ID=0xbc8(3016)[200分]
- 急,急,万分火急!(有关软件工程论文)
- 求助。NET数据库链接问题
- 高分求《c#精髓》和《thinking in c#》两套书的中英文版!
- 请教一个数据报大小的问题
- 怎樣擴展DATAGRID控件(WINFORM)?
select * from yourTable where title ='aaa' and author = 'fefe' and name = 'name'
.查询时用datagrid显示所有的查询结果(数据库中有表:cateory, report,其中cateory.cd_cateory=report.cd_cateory),怎样使datagrid每次均绑定不同的查询结果?
每次查询后对datagrid重新绑定!
如何实现当点击datagrid中任意一行时显示另一页:result.aspx,
在datagrid中使用按钮列,用select的事件.然后用C#写一个执行windows.open()的javascript脚本就行了!
我们的项目都是这么做的
在你绑定的DataGrid的ItemDataBound事件中处理,如:private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex > -1)
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('e',this.style.backgroundColor);this.style.cursor='hand';this.style.backgroundColor='#dddddd'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('e');"); e.Item.Attributes.Add("onclick","javascript:window.open('result.aspx?id="+ e.Item.Cells[0].Text +"');" );
}
}
e.Item.Attributes.Add("onclick","javascript:window.open('result.aspx?id="+ e.Item.Cells[0].Text +"');" );//单击时打开result.aspx,并传递参数id,你可以在result.aspx页中处理传递来的参数如果再搞不定的话,发个短消息给我!!!
2.在1.判断的基础上适当修改sql语句中的where子句,增加或减少几个条件即可OK!