<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 248px; WIDTH: 624px; POSITION: absolute; TOP: 104px; HEIGHT: 272px"
cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD style="HEIGHT: 51px" align="center" colSpan="2">员工信息模糊查询</TD>
</TR>
<TR>
<TD style="WIDTH: 222px; HEIGHT: 46px">请选择查询类型:</TD>
<TD style="HEIGHT: 46px"><asp:dropdownlist id="search_type" Runat="server">
<asp:ListItem Value="姓名" Selected="True"></asp:ListItem>
<asp:ListItem Value="性别"></asp:ListItem>
<asp:ListItem Value="籍贯"></asp:ListItem>
<asp:ListItem Value="民族"></asp:ListItem>
<asp:ListItem Value="学历"></asp:ListItem>
<asp:ListItem Value="部门"></asp:ListItem>
</asp:dropdownlist></TD>
</TR>
<TR>
<TD style="WIDTH: 222px; HEIGHT: 44px">请输入查询内容:</TD>
<TD style="HEIGHT: 44px"><asp:textbox id="txtcontent" Runat="server"></asp:textbox><asp:button id="button1" Runat="server" Text="确定"></asp:button></TD>
</TR>
<tr>
<td style="HEIGHT: 41px" align="center" colSpan="2"><FONT face="宋体">查询结果显示</FONT></td>
</tr>
<tr>
<td colSpan="2"><asp:datagrid id="grid_show" Runat="server" AutoGenerateColumns="False" GridLines="None" Width="616px"
AllowSorting="True" AllowPaging="True" CellPadding="2">
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" BackColor="Tan"></HeaderStyle>
<FooterStyle BackColor="Tan"></FooterStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="users_id" DataNavigateUrlFormatString="person_detail.aspx?users_id={0}"
DataTextField="users_id" HeaderText="员工编号">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="username" SortExpression="username" HeaderText="姓名">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="sex" SortExpression="sex" HeaderText="性别">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="hometown" SortExpression="hometown" HeaderText="籍贯">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="nation" SortExpression="nation" HeaderText="民族">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="dep_name" SortExpression="dep_name" HeaderText="部门">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="users_id" HeaderText="users_id"></asp:BoundColumn>
</Columns>
</asp:datagrid></td>
</tr>
</TABLE>
这是.aspx,

解决方案 »

  1.   

    string sql="select * from table where username like '%'"+this.dropdown.selecttext+"'%'
      

  2.   

    可是我的dropdown中不只有姓名 还有其他字段啊
      

  3.   

    用户一次只能从DropDownList中选一个东西出来,如果用户可以复选多项,你应该使用CheckBoxList
      

  4.   

    那如果我在查询类型中选择一项(姓名),在输入内容中输入一个员工的姓名 然后点击“确定”按纽 
    这个sql语句怎么编写,才能绑定到datagrid呢?
      

  5.   

    你在哪里输入?再加一个文本框?
    那么组合框的每一个value要和数据库的字段名一一对应string sql="select * from table where " + this.dropdown.Value + "" like '%'"+ this.TextBox1.Text + "'%'
      

  6.   

    string sql="select * from table where " + this.dropdown.Value + " like '%'"+ this.TextBox1.Text + "'%'
      

  7.   

    "><asp:dropdownlist id="search_type" Runat="server" onselectedindexchange="selectChange" autopostback="true">后台代码
    protected void selectChange()
    {
      respose.redircet("SearchResult.aspx?cid="+ddl.selectedItem.Value+"&string="+;lable.Text);
    }
    dropdownlist 定义好value和text 对应 如:value=1 text="名称"
    然后在searchresult.aspx页面接收条件
    sql语句这样写:
    string cid=request.querystring["cid"];
    string str=request.querystring["string"];
    string Query="select * from 表 where 1=1";
    if (cid=="1")
    {Query+=" and 名称字段 like '%"+str+"%'"}
    if (cid=="2")
    {Query+=" and 内容字段 like '%"+str+"%'"}
    依此类推
    这样明白不?
      

  8.   

    请选择查询类型:
    <asp:dropdownlist id="search_type" Runat="server">
       <asp:ListItem Value="姓名" Selected="True"></asp:ListItem>
       <asp:ListItem Value="性别"></asp:ListItem>
       <asp:ListItem Value="籍贯"></asp:ListItem>选择查询类型:<asp:textbox id="txtcontent" Runat="server"></asp:textbox><asp:button id="button1" Runat="server" Text="确定"></asp:button><asp:datagrid id="grid_show" Runat="server" AutoGenerateColumns="False" GridLines="None" Width="616px">
      

  9.   

    如果我选择“姓名”,在txtcontent中输入个名字,在datagrid中显示查询后的信息
      

  10.   

    <asp:dropdownlist id="search_type" Runat="server">
       <asp:ListItem Value="数据库里姓名的字段名" Selected="True">姓名</asp:ListItem>
       <asp:ListItem Value="数据库里性别的字段名">性别</asp:ListItem>
       <asp:ListItem Value="数据库里籍贯的字段名">籍贯</asp:ListItem>
       </asp:dropdownlist>
         选择查询类型:<asp:textbox id="txtcontent" Runat="server"></asp:textbox><asp:button id="button1" Runat="server" Text="确定" OnClick="button1_Click"></asp:button>   
        </div>    protected void button1_Click(object sender, EventArgs e)
        {
            string sql = "select * from table where " + this.search_type.SelectedValue + " like '%" + this.txtcontent.Text + "%'";        Response.Write(sql);
        }
      

  11.   

    protected void button1_Click(object sender, EventArgs e)
        {
            string sql = "select * from table where " + this.search_type.SelectedValue + " like '%" + this.txtcontent.Text + "%'";
    BindGrid();  //绑定datagrid就可以了吗?
    }
      

  12.   

    string s = "";
    for(int i =0 ;i<dropdownlist.Items.Count;i++)
    {
         s += dropdownlist.Item[i].ToString();}
    string sql = "select * from table where username like '%"+s+"%'";
      

  13.   

    //查找商品
        public DataSet SearchProduct(int start,string key, string way, string price, string category,int sorts)
        {
            Ds = new DataSet();
            string Query = "select * from product where 1=1";
            if (way != "")
            {
                switch (way)
                {
                    case "1":
                        Query += " and name like '%" + key + "%'";
                        break;
                    case "2":
                        Query += " and introduce like '%" + key + "%'";
                        break;
                    case "3":
                        Query += "and detail like '%" + key + "%'";
                        break;
                    case "4":
                        Query += "and  like '%" + key + "%'";
                        break;
                }
            }
            if (price != "")
            {
                double p = Convert.ToDouble(price);
                switch (price)
                {
                    case "1":
                        break;                    
                    case "2":
                        Query += " and price2<10" ;
                        break;
                    case "3":
                        Query += " and price2<20" ;
                        break;
                    case "4":
                        Query += " and price2<50";
                        break;
                    case "5":
                        Query += " and price2<100";
                        break; 
                    case "6":
                        Query += " and price2<500"; 
                        break; 
                    case "7":
                        Query += " and price2>=500";
                        break;
                }        }
            if (category != "")
            {
                
                if (category != "all")
                {
                    int c = Convert.ToInt32(category);
                    Query += " and categoryid="+c;
                }
            }
            if (sorts != 0)
                Query += " and sortsid=" + sorts;
            SqlDa = new SqlDataAdapter(Query,SqlConn);
            SqlDa.Fill(Ds,start,20,"product");
            SqlConn.Close();
            return Ds;
        }
      

  14.   

    killau(大柄)
    我能再问你个问题吗?