小妹初学asp.net,所用工具为web developer 2005。做一订单查询界面,用dropdownlist选择“按订单号查询“或“按客户名查询“,在textbox中输入相关信息,在按button实现查询。无信息时,显示“无相关信息“。该如何传递dropdownlist和textbox中的信息,如何实现查询?请大哥们帮小妹填写下代码,毕设急用!承诺100分!<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">    protected void Page_Load(object sender, EventArgs e)
    {    }    protected void Button1_Click(object sender, EventArgs e)
    {    }    protected void Button1_Click1(object sender, EventArgs e)
    {
        
    }
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
    </div>
        &nbsp;&nbsp;&nbsp;<asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value="ord_id">按订单号</asp:ListItem>
            <asp:ListItem Value="ord_customer">按客户名</asp:ListItem>
        </asp:DropDownList>
        &nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="查询" /><br />
        &nbsp; &nbsp;
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GoodsConnectionString %>"
            SelectCommand="SELECT * FROM [orders]"></asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="406px">
        </asp:GridView>
    </form>
</body>
</html>

解决方案 »

  1.   

    可以参考:
    http://feiren1421.cnblogs.com/archive/2006/04/05/367537.html
      

  2.   

    你这样的做法,我还真不会呀,哈哈,不知道是不是我落伍了,我从不把数据源及查询语句写到ASPX里的
      

  3.   

    不是太看懂你的意思,实现的就是条SQL语句的查询吗?
    protected void Button1_Click1(object sender, EventArgs e)
    {
           //连接数据库就没写了
           string sql = "select * from [表名] where" + dropdownlist.value + "='"+textbox.text+"'";
           DataSet ds = new DataSet() ;
           SqlDataAdapter da = new SqlDataAdapter(sql);
           da.fill(ds);
           然后在ds中取值
           如果有值就把数据源设给DataGrid,没有就为空
    }
      

  4.   

    如dropdownlist.value取不到值用dropdownlist.selectedvalue看看
    我忘记是哪个了~_~!!
      

  5.   

    if(dropdownlist1.SelectedItem.Text=="按订单号查询")
       {
         sql="select * from yourtable where 订单号字段='"+TextBox1.Text+"'";//TextBox1是你输入的订单的值.
       }
    else
      {
     sql="select * from yourtable where 客户名字段='"+TextBox1.Text+"'";//TextBox1是你输入的客户名的值.
      }
    conn.Open();
    SqlCommand cmd = new SqlCommand(sql,conn);
    SqlDataReader dr = cmd.ExecuteReader();
    conn.Close();
      

  6.   

    if(dropdownlist1.SelectedItem.Text=="按订单号查询")
       {
         sql="select * from yourtable where 订单号字段='"+TextBox1.Text+"'";//TextBox1是你输入的订单的值.
       }
    else
      {
     sql="select * from yourtable where 客户名字段='"+TextBox1.Text+"'";//TextBox1是你输入的客户名的值.
      }
    SqlDataSource.SelectCommand=sql;
      

  7.   

    //****在数据传输,屋一个共公函数//*****按选择类型进行查找
    private string SQLBulite()
    {
       string strSQL="";   if(drpliste.selectedindex==1)
       {
            //****按产品名称查找
            strSQL+="AND PRODUCTNAME LIKE '%" + TXTPRODUCTNAME.Value + "%'";
       }
       else if(drpliste.SelectedIndex==2)
       {
            //****按产品编号查找
            strSQL+=" AND PRODUCTID='" + TXTPRODUCTNAME.Value + "'";
       }   return strSQL;
    }//*****邦定数据
    private void PageLoadData()
    {
       int PageCurrentindex,PageCount;
       string strSQL="";
       //****获取查找条件
       strSQL=SQLBulite();
       strSQL+=" AND PRODUCTSTATE=2";   DataSet DSet=(new webservices.FrindService()).ProductInfo_Get_PageProc(out PageCurrentindex,out Page,strSQL,Asp.currentindex,Asp.PageSize);//****邦定数据.}
      

  8.   

    其实还有更简单的代码!
    DropDownList不是有个ValueMember和TextMember(应该是吧,那个智能感知最大的坏处就是让人记不住那些属性名),把TextMember设置成"按订单号查询"和"按姓名查询",ValueMember设置成"订单号字段"和"姓名字段",一句话就可以解决了!
    select * from Table where this.ddl1.selectValue.ToString()="'"+this.TextBox1.Text.Trim()+"'"
    不需要要判断语句了!
      

  9.   

    至于判断是否有信息,更简单啊,如果用DataSet,则直接判断表的行数就可以了,参考如下:OleDbDataAdapter sda=new OleDbDataAdapter();
    sda.SelectCommand=new OleDbCommand("select * from table where "+this.ddl1.SelectValue.ToString()+"='"+this.TextBox1.Text.Trim()+"'",con);
    DataSet ds=new DataSet();
    sda.Fill(ds,"tab");
    if(ds.Tables["tab"].Rows.Count==0)
    {}
    else
    {}顺便说一句,我上面那个SQL语句有点问题,应该是这个!