default.aspx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Category1Button_Click(object sender, EventArgs e)
  6. {
  7. SqlDataSource1.SelectParameters[0].DefaultValue = "1";
  8. }
  9. protected void Category2Button_Click(object sender, EventArgs e)
  10. {
  11. SqlDataSource1.SelectParameters[0].DefaultValue = "2";
  12. }
  13. </script>
  14. <html xmlns="http://www.w3.org/1999/xhtml">
  15. <head runat="server">
  16. <title>Products Display</title>
  17. </head>
  18. <body>
  19. <form id="form1" runat="server">
  20. <div>
  21. <asp:ScriptManager ID="ScriptManager1" runat="server">
  22. </asp:ScriptManager>
  23. <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
  24. <ContentTemplate>
  25. <asp:Button ID="Category1Button" runat="server" Text="Category 1" OnClick="Category1Button_Click" />
  26. <asp:Button ID="Category2Button" runat="server" OnClick="Category2Button_Click" Text="Category 2" />
  27. <asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSource1"
  28. Width="231px">
  29. <ItemTemplate>
  30. ProductName:
  31. <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>'>
  32. </asp:Label><br />
  33. ProductID:
  34. <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label><br />
  35. <br />
  36. </ItemTemplate>
  37. </asp:DataList>
  38. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  39. SelectCommand="SELECT [ProductName], [ProductID] FROM [Alphabetical list of products] WHERE ([CategoryID] = @CategoryID)">
  40. <SelectParameters>
  41. <asp:Parameter DefaultValue="1" Name="CategoryID" Type="Int32" />
  42. </SelectParameters>
  43. </asp:SqlDataSource>
  44. </ContentTemplate>
  45. <Triggers>
  46. <asp:AsyncPostBackTrigger ControlID="Category1Button" />
  47. <asp:AsyncPostBackTrigger ControlID="Category2Button" />
  48. </Triggers>
  49. </asp:UpdatePanel>
  50. </div>
  51. </form>
  52. </body>
  53. </html>