我在一邊發現了我的問題的實現,但我不知道爲什麼它不工作。當我把一些值放入文本框時,它應該爲我做一個回發,但它不會。AJAX asp Web表格在網格中搜索
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txt" />
</Triggers>
<ContentTemplate>
<asp:TextBox runat="server" ID="TextBox1" AutoPostBack="true" OnTextChanged="txt_TextChanged"></asp:TextBox>
<asp:GridView runat="server" ID="GridView2">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ItemStyle-Font-Size="10px" />
<asp:BoundField DataField="regon" HeaderText="Regon" SortExpression="regon" ItemStyle-Font-Size="10px" />
<asp:BoundField DataField="nip" HeaderText="NIP" SortExpression="nip" ItemStyle-Font-Size="10px" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
而後面的代碼:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txt.Attributes.Add("onkeyup", "javascript:setTimeout('__doPostBack(\'txt\',\'\')', 0)");
string SelectCommand = "SELECT * " +
" FROM client_inf WHERE amount > 1000";
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(SelectCommand, conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
conn.Close();
}
}
protected void txt_TextChanged(object sender, EventArgs e)
{
if (txt.Text != "")
{
string SelectCommand = "SELECT * " +
" FROM client_inf WHERE client_name Like '" + txt.Text + "%'"
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(SelectCommand, conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
conn.Close();
}
}
http://www.infosearchshop.com/21-gridview-search-as-you-type-with-ajax
請改變'內的 '到'的 ' TextBox的ID不匹配。 –
Rainmaker