[英]Searching with SQL Server database
I'm currently working on a website project and I'm almost done, except that I need to get my searching to work. 我目前正在研究一个网站项目,并且几乎完成了,除了需要进行搜索之外。
I would like it to work like this: On my masterpage there is a asp:textbox
and a asp:button
. 我希望它像这样工作:在我的母版页上有一个asp:textbox
和一个asp:button
。 When I type in a search word and click on my button I would like it to redirect to a search.aspx page - The problem is, that I don't know how to do that. 当我输入搜索词并单击我的按钮时,我希望它重定向到search.aspx页面-问题是,我不知道该怎么做。 I only got the method and it looks like this 我只有方法,看起来像这样
public DataTable Search(string Keyword)
{
return db.GetData(
"SELECT fldTitle, fldLang, fldCode from tblSnipets LIKE @1",
"%" + Keyword + "%");
}
From there I don't know what to do. 从那里我不知道该怎么办。
Using classic ASP.NET and PostBack event without any patterns it will look like this: 使用没有任何模式的经典ASP.NET和PostBack事件,它将看起来像这样:
1 - Add an event handler to the button click event. 1-将事件处理程序添加到按钮单击事件。
<asp:Button id="Button1" Text="Search" OnClick="SearchBtn_Click" runat="server"/>
2 - Add SearchBtn_Click handler to the code behind file of your page and do a redirect to your Search page. 2-将SearchBtn_Click处理程序添加到页面文件后面的代码中,并重定向到搜索页面。 it will look like this: 它看起来像这样:
void SearchBtn_Click(Object sender, EventArgs e)
{
}
3 - In this event handler write code that will redirect to your Search.aspx with parameters of your search criteria: 3-在此事件处理程序中,编写代码,该代码将使用搜索条件的参数重定向到Search.aspx:
Response.Redirect("~/Search.aspx?criteria=" + Server.HtmlEncode(myTextBox.Text));
or close to this statement (check the MSDN) 或接近此声明(请检查MSDN)
4 - On the Search.aspx code behinf page in the Page_Load handler catch the parameters and call your method to get the data. 4-在Page_Load处理程序的Search.aspx代码后页上,捕获参数并调用您的方法以获取数据。
This is not the best solution, but it should work. 这不是最好的解决方案,但它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.