SearchResultsWithoutUpdatePanelCS.aspx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. protected void Search_Click(object sender, EventArgs e)
  6. {
  7. SqlDataSource1.SelectParameters["SearchTerm"].DefaultValue =
  8. Server.HtmlEncode(SearchField.Text);
  9. Label1.Text = "Searching for '" +
  10. Server.HtmlEncode(SearchField.Text) + "'";
  11. }
  12. protected void ExampleProductSearch_Click(object sender, EventArgs e)
  13. {
  14. SqlDataSource1.SelectParameters["SearchTerm"].DefaultValue =
  15. Server.HtmlEncode(ExampleProductSearch.Text);
  16. Label1.Text = "Searching for '" +
  17. Server.HtmlEncode(ExampleProductSearch.Text) + "'";
  18. SearchField.Text = ExampleProductSearch.Text;
  19. }
  20. </script>
  21. <html xmlns="http://www.w3.org/1999/xhtml">
  22. <head id="Head1" runat="server">
  23. <title>UpdatePanel Trigger Example</title>
  24. <style type="text/css">
  25. body {
  26. font-family: Lucida Sans Unicode;
  27. font-size: 10pt;
  28. }
  29. button {
  30. font-family: tahoma;
  31. font-size: 8pt;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <form id="form1" runat="server"
  37. defaultbutton="SearchButton" defaultfocus="SearchField">
  38. <div>
  39. Search for products in the Northwind database. For example,
  40. find products with
  41. <asp:LinkButton ID="ExampleProductSearch" Text="Louisiana" runat="server" OnClick="ExampleProductSearch_Click">
  42. </asp:LinkButton> in the title.&nbsp;<br /><br />
  43. <asp:TextBox ID="SearchField" runat="server"></asp:TextBox>
  44. <asp:Button ID="SearchButton" Text="Submit" OnClick="Search_Click"
  45. runat="server" />
  46. <fieldset>
  47. <legend>Northwind Products</legend>
  48. <asp:Label ID="Label1" runat="server"/>
  49. <br />
  50. <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
  51. AllowSorting="True" DataSourceID="SqlDataSource1">
  52. <EmptyDataTemplate>
  53. No results to display.
  54. </EmptyDataTemplate>
  55. </asp:GridView>
  56. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  57. ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  58. SelectCommand="SELECT [ProductName], [UnitsInStock] FROM
  59. [Alphabetical list of products] WHERE ([ProductName] LIKE
  60. '%' + @SearchTerm + '%')">
  61. <SelectParameters>
  62. <asp:Parameter Name="SearchTerm" Type="String" />
  63. </SelectParameters>
  64. </asp:SqlDataSource>
  65. </fieldset>
  66. </div>
  67. </form>
  68. </body>
  69. </html>