私は自分のウェブサイトをインスタント検索(キーダウンで検索)したいのですが、それを行うための良い方法が本当にわかりません。今までは「Enter」キーで検索していました。
私はこのコードを持っています:
<div id="mainsearch" class="search">
<input class="text-input" value="SEARCH" style="color:#aaa" type="text" id="searchbox" onkeydown="if (event.keyCode == 13){document.getElementById('searchLink').click();return false;}" maxlength="50" runat="server" />
<asp:LinkButton ID="searchLink" runat="server" onclick="searchLink_Click">Search</asp:LinkButton>
<div id="results" visible="false" class="ac_results" style="position: absolute; width: 298px;" runat="server">
<asp:Literal ID="litActiveSearch" runat="server"></asp:Literal>
</div>
</div>
そして私の背後にあるコード:
protected void searchLink_Click(object sender, EventArgs e)
{
results.Visible = true;
litActiveSearch.Text = SearchResults(searchbox.Value);
}
private string SearchResults(string searchString = "")
{
SqlCommand projectCom = new SqlCommand();
....
countCom.CommandText = "SELECT count(ID_PROJECT) FROM PROJECT WHERE TITLE LIKE '%" + searchString + "%' AND DELETE_BIT = 'False' ";
countCom.CommandType = CommandType.Text;
//int projectRowCount=0,actorRowCount=0,mediaRowCount = 0;
int RowCount = 0;
RowCount = Convert.ToInt32(countCom.ExecuteScalar());
/*str += "<div class=\"ac_results\" style=\"position: absolute; width: 251px; top: 110.4444465637207px;" +
"left: 1010.8776870117188px;\">";*/
str += "<ul>";
str += " <li class=\"ac_even ac_over\"><a href=\" ../search/search.aspx?q=" + searchString + " \" class=\"startsearch\">St<strong>a</strong>rt <strong>" +
"a</strong> full se<strong>a</strong>rch ></a>" +
"</li>";
str += " <li class=\"ac_odd\">" +
"<span class=\"category\">" +
"Projects<a class=\"more\" href=\" ../search/searchProjects.aspx?q=" + searchString + " \" >" + RowCount.ToString() + " results ></a>" +
"</span>" +
"</li>";
//************ Now show the results ************//
projectCom.CommandText = "SELECT TOP 3 ID_PROJECT,TITLE,COUNTRY FROM PROJECT WHERE TITLE LIKE '%" + searchString + "%' AND DELETE_BIT = 'False'";
....
}
SearchResults()
メソッドでは、画面に結果を表示するためにデータベースと接続するクエリを実行します。
ウェブサイトを作るのは初めてなので、何も知りません。