C# asp.NETC高级搜索

C# asp.NETC高级搜索,c#,asp.net,search,C#,Asp.net,Search,在站点im上,您可以看到当前正在重复数据库中的所有配置文件 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <div class="profilbox"> <div id="billedeSmall">

在站点im上,您可以看到当前正在重复数据库中的所有配置文件

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">

    <ItemTemplate>

               <div class="profilbox">
                    <div id="billedeSmall">
                        <img alt="" src="prod_image/<%#Eval ("bruger_billede") %>" width="100" height="100" />
                        </div>
                <h3><%# Eval("bruger_fornavn") %><br /><%# Eval("bruger_efternavn") %></h3>
                <p>Alder: <%# Eval("bruger_alder") %>år.<br />Søger: <%# Eval("bruger_søger") %><br />Kommune: <%# Eval("bruger_kommune") %>
                   <br /><a href="profilNormal.aspx?id=<%#Eval("bruger_id") %>">...Vis profil</a></p>

            </div>

        </ItemTemplate>

    </asp:Repeater>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>" SelectCommand="SELECT  * FROM brugere ORDER BY NEWID()"></asp:SqlDataSource>

该网站的图片可以得到更好的说明:

这几乎可以用,但kommune仍然不能100%工作

受保护的无效按钮搜索\u单击对象发件人,事件参数e {


我认为您需要从“代码隐藏”的按钮单击事件开始。基本上,您可以通过检查下拉选择值、文本框输入和基于这些值搜索数据库来构建逻辑。
<table class="auto-style3">
    <tr>
        <td class="auto-style4">vis profiler der søger:</td>
        <td>
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>mand</asp:ListItem>
                <asp:ListItem>kvinde</asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td class="auto-style4">age between: </td>
        <td>
            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            og<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="auto-style5">i kommunen:</td>
        <td class="auto-style6">
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="auto-style4">&nbsp;</td>
        <td>
            <asp:Button ID="Button1" runat="server" Text="Søg" OnClick="Button1_Click" />
        </td>
    </tr>
</table>
 protected void ButtonSearch_Click(object sender, EventArgs e)
    {



        string statement = @"SELECT * FROM brugere";

        string whereConcatenator = "WHERE ";

        if (DropDownListSøger.SelectedItem != null)
        {
            statement += whereConcatenator;
            statement += "bruger_søger= '" + DropDownListSøger.SelectedItem.Value + "' ";

            whereConcatenator = "OR ";
        }

       if (TextBoxKommune.Text.Length > 0)
        {
            statement += whereConcatenator;
            statement += "bruger_kommune LIKE '%" + TextBoxKommune.Text + "%' ";

            whereConcatenator = "OR ";
        }


        Response.Write(statement);

        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = Conn;
        cmd.CommandType = CommandType.Text;
        cmd = new SqlCommand(statement, Conn);

        Conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();


        while (reader.Read())
        {

        }
    string statement = @"SELECT * FROM brugere";

    string whereConcatenator = " WHERE ";

    if (DropDownListSøger.SelectedItem != null)
    {
        statement += whereConcatenator;
        statement += "bruger_søger ='" + DropDownListSøger.SelectedItem.Value + "' ";

        whereConcatenator = "AND ";
    }


    if (TextBox_AlderFra.Text != "")
      {

         statement += whereConcatenator;
         statement += " bruger_alder BETWEEN '" + TextBox_AlderFra.Text + "' AND '" + TextBox_AlderTil.Text + "'";
         whereConcatenator = "AND ";

     }
    if (TextBoxKommune.Text.Length > 0)
    {
        statement += whereConcatenator;
        statement += "bruger_kommune = '%" + TextBoxKommune.Text + "%' ";

    }

   SqlDataSource1.SelectCommand = statement;


}