注册 登录
编程论坛 ASP.NET技术论坛

查询

馨馨 发布于 2008-04-16 13:24, 822 次点击
我想用一个DropDownlist将数据库总的字段显示出来,在用一个TEXTBOX显示如果选定了DropDownlist中的某个字段,然后就在TEXTBOX里输入这个字段下面的值,再在数据库中找出来,例如:我在DropDownlist中选择了货号,然后在TEXTBOX中输入一个货号比如10011,然后点击查询到数据库中查找,这中查询该怎么做呢?
6 回复
#2
ilovetea2008-04-16 13:31
protected void Button1_Click1(object sender, EventArgs e)
    {
        if (this.DropDownList1.SelectedValue == "学号或姓名")
        {
            this.GridView1.DataSourceID = "AccessDataSource2006xuehao";
            this.GridView2.DataSourceID = "AccessDataSource2005xuehao";
            this.GridView3.DataSourceID = "AccessDataSource2007xuehao";
        else if (this.DropDownList1.SelectedValue == "家长姓名或工作单位")
      }  {
            this.GridView1.DataSourceID = "AccessDataSource2006jiazhang";
            this.GridView2.DataSourceID = "AccessDataSource2005jiazhang";
            this.GridView3.DataSourceID = "AccessDataSource2007jiazhang";
        }
#3
hebingbing2008-04-16 13:36
将你的dropdownlist的autopostback设置成ture,然后在它的selectedindexchanged事件中将它的值赋给textbox,然后在你的按钮的click事件中写上sql查询,where ……=textbox1.text.tostring().trim()
#4
馨馨2008-04-16 13:46
但是在写SQL语句的时候WHERE后面应该怎么写呢,怎么才能将textbox1.text.tostring().trim()付给它想要的字段呢是不是得一句一句的写呢,比如字段名是newsid,newsname就应该写 newsid= textbox1.text.tostring().trim() || newsname =textbox1.text.tostring().trim()
#5
馨馨2008-04-16 14:04
在它的selectedindexchanged事件中将它的值赋给textbox的是侯 我用的代码是
DropDownList1.SelectedValue == "pinming.Text.tostring().trim()";
怎么错了呢
#6
馨馨2008-04-16 14:06
系统提示错误    
1    只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句    C:\Inetpub\wwwroot\pp\mhchazhao.aspx.cs    126    9    C:\...\pp\
这是怎么回事呢
#7
馨馨2008-04-16 16:03
解决了 我使用了switch语句实现了,谢谢大家的帮助
1