<div>
        <asp:Label ID="Label1" runat="server" Text="价格"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Width="50px"></asp:TextBox>元—
        <asp:TextBox ID="TextBox2" runat="server" Width="61px"></asp:TextBox>元<br />
        <br />
        克拉<asp:TextBox ID="TextBox3" runat="server" Width="58px"></asp:TextBox>—<asp:TextBox
            ID="TextBox4" runat="server" Width="55px"></asp:TextBox><br />
        <br />
       切工<br />
        <asp:CheckBoxList ID="Cu11" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem>理想</asp:ListItem>
            <asp:ListItem>非常好</asp:ListItem>
            <asp:ListItem>好</asp:ListItem>
            <asp:ListItem>一般</asp:ListItem>
        </asp:CheckBoxList>
        颜色  <asp:CheckBoxList ID="Color1" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem>D</asp:ListItem>
            <asp:ListItem>E</asp:ListItem>
            <asp:ListItem>F</asp:ListItem>
            <asp:ListItem>G</asp:ListItem>
            <asp:ListItem>H</asp:ListItem>
            <asp:ListItem>I</asp:ListItem>
            <asp:ListItem>J</asp:ListItem>
        </asp:CheckBoxList></div>
        净度<asp:CheckBoxList ID="jingdu1" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem>FL</asp:ListItem>
            <asp:ListItem>IF</asp:ListItem>
            <asp:ListItem>VVS1</asp:ListItem>
            <asp:ListItem>VVS2</asp:ListItem>
            <asp:ListItem>VS1</asp:ListItem>
            <asp:ListItem>VS2</asp:ListItem>
            <asp:ListItem>SI1</asp:ListItem>
            <asp:ListItem>SI2</asp:ListItem>
        </asp:CheckBoxList><br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="搜索" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
我想实现点击搜索能根据上面输入的情况在数据库里进行联合查询,查询后结果显示在下面Gridview上,我写了很小部分其他的,其他的因为本人刚入ASP.NET门编程能力还不是很强,还行高手帮一下忙,谢谢,附我写的那段
protected void Button1_Click(object sender, EventArgs e)
    {
        string cost1 = TextBox1.Text.Trim();
        string cost2 = TextBox2.Text.Trim();
        string kela1 = TextBox3.Text.Trim();
        string kela2 = TextBox4.Text.Trim();
       
        foreach (ListItem cut in this.Cu11.Items)
        {
            if (cut.Selected)
            {
                
            }
 
        }
       
        foreach (ListItem Col in Color1.Items)
        {
            if (cut.Selected)
            {            }        }
        foreach (ListItem jingdu in jingdu1.Items)
        {
            if (jingdu.Selected)
            {            }        }
        OleDbConnection con = new OleDbConnection("server=.;database=myDB;uid=sa;pwd=123456");
        
    }数据库里价格,克拉,颜色,净度列分别是Rate,Carat,Col,Cut,Pur

解决方案 »

  1.   

    http://download.csdn.net/source/625018
      

  2.   

    http://download.csdn.net/source/625018哥们,请不要恶意灌水
      

  3.   

    1。界面显示
      Cu11.DataSource   =   ds.Tables[0];//所有选项存到数据库
      Cu11.DataTextField   =   "name ";
      Cu11.DataValueField   =   "id ";
      Cu11.DataBind();2。读取选中项保存到数据库的方法
    string   checkName=   " ";
                            for   (int   i   =   0;   i   <   Cu11.Items.Count;   i++)
                            {
                                    if   (Cu11.Items[i].Selected)
                                    {
                                            checkName+=   Cu11.Items[i].Value   +   "| ";
                                    }
                            }
                            if   (checkName!=   " ")
                            {
                                    checkName=   checkName.Substring(0,   otherdept.Length   -   1);
                            }
    然后把checkName保存到你的表的一列里。3。从数据库读取绑定在页面的方法:
    string   checkName=从数据库读取保存的那列。
    string[]   checkNames;
    checkNames=   checkName.Split( '| ');
    for   (int   i   =   0;   i   <   checkNames.Length;   i++)
    {
              Cu11.Items.FindByValue(checkNames[i]).Selected   =   true;
      

  4.   

    都取出值来了吧?lz是不知如何在DropDownList里取出所选项目的值来呢 还是不知道用这些值怎么写sql查询呢?
    取值:string aa = DropDownList.SelectedValuesql:WHERE XXX = (CASE WHEN aa = '' then XXX ELSE THEN aa END)
         ...
      

  5.   

    "数据库里价格,克拉,颜色,净度列分别是Rate,Carat,Col,Cut,Pur"你的这个跟本就不对应呀????我都用汉字标出来了,你自己改。  
          string sqlstr="select * from 表 where  (价格 between {0} and {1})  and (克拉 between {2} and {3} ) and 切工='{4}'"
                   sqlstr+="  and 颜色='{5}' and 净度='{6}'";        sqlstr=string.Format(sqlstr,TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox4.Text
                ,Cu11.SelectedValue,Color1.SelectedValue,jingdu1.SelectedValue);
            //执行上面的sql语句。先学个写法吧。等你熟练了之后,将这语句改用存储过程(建议)。
      

  6.   

            sqlstr=string.Format(sqlstr,TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox4.Text
                ,Cu11.SelectedValue,Color1.SelectedValue,jingdu1.SelectedValue);
    这个语法有问题啊,Cu11.SelectedValue不用循环吗
      

  7.   

    "数据库里价格,克拉,颜色,净度列分别是Rate,Carat,Col,Cut,Pur" 就是说页面上的价格,克拉,颜色,净度,对应数据库里的列名分别是Rate,Carat,Col,Cut,Pur,求一个正确,完整版的,求助中~~~~~~~~
      

  8.   

    "数据库里价格,克拉,颜色,净度列分别是Rate,Carat,Col,Cut,Pur" 就是说页面上的价格,克拉,颜色,净度,对应数据库里的列名分别是Rate,Carat,Col,Cut,Pur,求一个正确,完整版的,求助中~~~~~~~~
      

  9.   

    Cu11,Color1,jingdu1都是要循环的不是吗?