[英]asp.net c# advanced searching
on a site im currently, as you can see repeating out all profiles from the database. 您目前可以在网站的即时通讯上看到,您会从数据库中重复所有配置文件。
<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>
and here a table with 1 drop down for "show profiles that are searching for" a row with 2 texboxes that are ment to be age between textbox1 and textbox2 and a last textbox where you can search for area. 在这里有一个表,其中有1个下拉列表,用于“显示正在搜索的配置文件”,其中包含2个texbox,该行的年龄介于textbox1和textbox2之间,以及最后一个可以在其中搜索区域的文本框。
<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"> </td>
<td>
<asp:Button ID="Button1" runat="server" Text="Søg" OnClick="Button1_Click" />
</td>
</tr>
</table>
and that is sadly all i have as i dont know where to start in code behind. 可悲的是,这就是我所拥有的,因为我不知道在后面的代码中从哪里开始。 i wanted it to work like : if you choose "male" in the dropdownlist and click the botton, show all profiles that have "male" in the database column called "looking for" or the other way around ofcourse. 我希望它的工作方式是:如果在下拉列表中选择“男性”并单击该按钮,则在数据库列中显示所有具有“男性”的配置文件,即“寻找”或其他方式。
and then if you enter something in age between: textbox4 and textbox5 show all profiles that then are male, and between say 20 and 30 if that is what the user entered in the two textboxes. 然后如果您输入的年龄介于以下两个之间:textbox4和textbox5将显示所有当时是男性的个人资料,如果用户在两个文本框中输入的是20至30之间,则显示该个人资料。 does this make sense? 这有意义吗? im still a beginner in ASP.net c#. 我仍然是ASP.net c#的初学者。 im sorry if this is not a real question. 抱歉,如果这不是一个真正的问题。
i now started on codebehind, is this the right idea? 我现在开始进行代码隐藏,这是正确的主意吗? and can anyone tell me how i should show the results on my page? 谁能告诉我如何在网页上显示结果? again im still new so please bear with me. 我还是很新,所以请忍受我。
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())
{
}
picture of the site to get a better illustration: 该网站的图片以获得更好的插图:
it almost works with this, but " kommune " still is not working 100 % 它几乎可以解决这个问题,但是“ kommune”仍然无法正常工作100%
protected void ButtonSearch_Click(object sender, EventArgs e) { 受保护的void ButtonSearch_Click(对象发送者,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 = "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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.