UpdatePanelExample2CS.aspx 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <script runat="server">
  4. protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  5. {
  6. SqlDataSource2.SelectParameters["OrderID"].DefaultValue =
  7. GridView1.SelectedDataKey.Value.ToString();
  8. }
  9. </script>
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11. <head id="Head1" runat="server">
  12. <title>UpdatePanel Example</title>
  13. </head>
  14. <body>
  15. <form id="form1" runat="server">
  16. <div>
  17. <asp:ScriptManager ID="ScriptManager1"
  18. runat="server" />
  19. <asp:UpdatePanel ID="OrdersPanel"
  20. UpdateMode="Conditional"
  21. runat="server">
  22. <ContentTemplate>
  23. <asp:GridView ID="GridView1"
  24. AllowPaging="True"
  25. AllowSorting="True"
  26. Caption="Orders"
  27. DataKeyNames="OrderID"
  28. DataSourceID="SqlDataSource1"
  29. OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
  30. runat="server" >
  31. <Columns>
  32. <asp:CommandField ShowSelectButton="True"></asp:CommandField>
  33. </Columns>
  34. </asp:GridView>
  35. <asp:SqlDataSource ID="SqlDataSource1"
  36. runat="server"
  37. ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  38. SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID], [OrderDate] FROM [Orders]">
  39. </asp:SqlDataSource>
  40. </ContentTemplate>
  41. </asp:UpdatePanel>
  42. <asp:UpdatePanel ID="OrderDetailsPanel"
  43. UpdateMode="Always"
  44. runat="server">
  45. <ContentTemplate>
  46. <asp:DetailsView ID="DetailsView1"
  47. Caption="Order Details"
  48. DataKeyNames="OrderID,ProductID"
  49. DataSourceID="SqlDataSource2"
  50. runat="server">
  51. <EmptyDataTemplate>
  52. <i>Select a row from the Orders table.</i>
  53. </EmptyDataTemplate>
  54. </asp:DetailsView>
  55. <asp:SqlDataSource ID="SqlDataSource2"
  56. ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  57. SelectCommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity], [Discount] FROM [Order Details] WHERE ([OrderID] = @OrderID)"
  58. runat="server">
  59. <SelectParameters>
  60. <asp:Parameter Name="OrderID"
  61. Type="Int32" />
  62. </SelectParameters>
  63. </asp:SqlDataSource>
  64. </ContentTemplate>
  65. </asp:UpdatePanel>
  66. </div>
  67. </form>
  68. </body>
  69. </html>