ChildTriggers.aspx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5. <title>UpdatePanel Example</title>
  6. <script runat="server">
  7. protected void ProductsUpdatePanel_Load(object sender, EventArgs e)
  8. {
  9. CategoryTimeLabel.Text = DateTime.Now.ToString();
  10. }
  11. protected void CategoriesRepeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
  12. {
  13. SubcategoriesDataSource.SelectParameters["CategoryID"].DefaultValue = e.CommandArgument.ToString();
  14. SubcategoriesRepeater.DataBind();
  15. ProductsDataSource.SelectParameters["SubcategoryID"].DefaultValue = "0";
  16. ProductsGridView.DataBind();
  17. }
  18. protected void SubcategoriesRepeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
  19. {
  20. ProductsDataSource.SelectParameters["SubcategoryID"].DefaultValue = e.CommandArgument.ToString();
  21. ProductsGridView.DataBind();
  22. }
  23. protected void RefreshCategoriesButton_Click(object sender, EventArgs e)
  24. {
  25. SubcategoriesDataSource.SelectParameters["CategoryID"].DefaultValue = "0";
  26. SubcategoriesRepeater.DataBind();
  27. ProductsDataSource.SelectParameters["SubcategoryID"].DefaultValue = "0";
  28. ProductsGridView.DataBind();
  29. }
  30. </script>
  31. </head>
  32. <body>
  33. <form id="form1" runat="server">
  34. <div>
  35. <asp:ScriptManager ID="ScriptManager1" runat="server">
  36. </asp:ScriptManager>
  37. <table>
  38. <tr>
  39. <td valign="top" style="width:120px">
  40. <asp:UpdatePanel ID="ProductsUpdatePanel" runat="server"
  41. ChildrenAsTriggers="False"
  42. OnLoad="ProductsUpdatePanel_Load" UpdateMode="Conditional">
  43. <ContentTemplate>
  44. <asp:Repeater ID="CategoryRepeater" runat="server" DataSourceID="CategoriesDataSource"
  45. OnItemCommand="CategoriesRepeater_ItemCommand">
  46. <ItemTemplate>
  47. <asp:LinkButton runat="server" ID="SelectCategoryButton"
  48. Text='<%# Eval("Name") %>'
  49. CommandName="SelectCategory"
  50. CommandArgument='<%#Eval("ProductCategoryID") %>' /><br />
  51. </ItemTemplate>
  52. </asp:Repeater>
  53. <asp:SqlDataSource ID="CategoriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
  54. SelectCommand="SELECT Name, ProductCategoryID FROM Production.ProductCategory ORDER BY ProductCategoryID">
  55. </asp:SqlDataSource>
  56. <br />
  57. <asp:Label ID="CategoryTimeLabel" runat="server" Text="Label" Font-Size="Smaller"></asp:Label>
  58. </ContentTemplate>
  59. <Triggers>
  60. <asp:AsyncPostBackTrigger ControlID="RefreshCategoriesButton" EventName="Click" />
  61. </Triggers>
  62. </asp:UpdatePanel>
  63. <asp:LinkButton runat="Server" ID="RefreshCategoriesButton" Text="Refresh Category List"
  64. OnClick="RefreshCategoriesButton_Click" Font-Size="smaller" />
  65. </td>
  66. <td valign="top">
  67. <asp:UpdatePanel ID="SubcategoriesUpdatePanel" runat="server">
  68. <ContentTemplate>
  69. <asp:Repeater ID="SubcategoriesRepeater" runat="server" DataSourceID="SubcategoriesDataSource"
  70. OnItemCommand="SubcategoriesRepeater_ItemCommand" >
  71. <ItemTemplate>
  72. <asp:LinkButton runat="server" ID="SelectSubcategoryButton"
  73. Text='<%# Eval("Name") %>'
  74. CommandName="SelectSubcategory"
  75. CommandArgument='<%#Eval("ProductSubcategoryID") %>' /><br />
  76. </ItemTemplate>
  77. </asp:Repeater>
  78. <asp:SqlDataSource ID="SubcategoriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
  79. SelectCommand="SELECT Name, ProductSubcategoryID FROM Production.ProductSubcategory
  80. WHERE Production.ProductSubcategory.ProductCategoryID = @CategoryID
  81. ORDER BY Name">
  82. <SelectParameters>
  83. <asp:Parameter Name="CategoryID" DefaultValue="0" />
  84. </SelectParameters>
  85. </asp:SqlDataSource>
  86. </ContentTemplate>
  87. </asp:UpdatePanel>
  88. </td>
  89. <td valign="top">
  90. <asp:UpdatePanel ID="ProductUpdatePanel" runat="server">
  91. <ContentTemplate>
  92. <asp:GridView ID="ProductsGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="ProductID" DataSourceID="ProductsDataSource" GridLines="Horizontal">
  93. <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
  94. <Columns>
  95. <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" >
  96. <ItemStyle Width="240px" />
  97. </asp:BoundField>
  98. </Columns>
  99. <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
  100. <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
  101. <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
  102. <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
  103. <AlternatingRowStyle BackColor="#F7F7F7" />
  104. </asp:GridView>
  105. <asp:SqlDataSource ID="ProductsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
  106. SelectCommand="SELECT ProductID, Name, ProductSubcategoryID FROM Production.Product WHERE (ProductSubcategoryID = @SubcategoryID) ORDER BY Name">
  107. <SelectParameters>
  108. <asp:Parameter DefaultValue="0" Name="SubcategoryID" />
  109. </SelectParameters>
  110. </asp:SqlDataSource>
  111. </ContentTemplate>
  112. </asp:UpdatePanel>
  113. </td>
  114. </tr>
  115. </table>
  116. </div>
  117. </form>
  118. </body>
  119. </html>