NorthwindTradersContentPageCS.aspx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <%@ Page Language="C#" MasterPageFile="NorthwindTradersMasterPageCS.master" Title="Content Page" %>
  2. <script runat="server">
  3. protected void Search_Click(object sender, EventArgs e)
  4. {
  5. SqlDataSource1.SelectParameters["SearchTerm"].DefaultValue =
  6. Server.HtmlEncode(SearchField.Text);
  7. Label1.Text = "Searching for '" +
  8. Server.HtmlEncode(SearchField.Text) + "'";
  9. }
  10. </script>
  11. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  12. <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
  13. <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
  14. <ContentTemplate>
  15. Product Search: <asp:TextBox ID="SearchField" runat="server"></asp:TextBox>
  16. <asp:Button ID="SearchButton" Text="Submit" OnClick="Search_Click"
  17. runat="server" />
  18. </ContentTemplate>
  19. </asp:UpdatePanel>
  20. <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always"
  21. runat="server">
  22. <Triggers>
  23. <asp:AsyncPostBackTrigger ControlID="SearchButton" />
  24. </Triggers>
  25. <ContentTemplate>
  26. <asp:Label ID="Label1" runat="server"/>
  27. <br />
  28. <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
  29. AllowSorting="True" DataSourceID="SqlDataSource1">
  30. <EmptyDataTemplate>
  31. No results to display.
  32. </EmptyDataTemplate>
  33. </asp:GridView>
  34. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  35. ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  36. SelectCommand="SELECT [ProductName], [UnitsInStock] FROM
  37. [Alphabetical list of products] WHERE ([ProductName] LIKE
  38. '%' + @SearchTerm + '%')">
  39. <SelectParameters>
  40. <asp:Parameter Name="SearchTerm" Type="String" />
  41. </SelectParameters>
  42. </asp:SqlDataSource>
  43. </ContentTemplate>
  44. </asp:UpdatePanel>
  45. </asp:Content>