asp.net ajax技巧2
來源:互聯網
上載者:User
下面是非同步一對多流程,有兩個gridview,上面一個gridview是主,下面一個GRIDVIEW顯示的是從,當點
主表的資料時,下面的GRIDVIEW顯示對應的資料(DETAIL),要注意的是,為了防止浪費時間,把兩個GRIDVIEW
放到兩個不同的
updatepannel中去,並且設計兩個UPDATEPANNEL控制項的updatemode屬性為conditional,這樣當在下方的GRIDVIEW控制項排序時,上方的UPDATEPANNEL控制項不會被局部更新
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="OrdersPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" AllowPaging="True" AllowSorting="True" Caption="訂貨主檔的訂單資料"
DataKeyNames="訂單號碼" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
runat="server" Width="608px" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" SelectedIndex="0"
OnPageIndexChanged="GridView1_PageIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True"></asp:CommandField>
</Columns>
<FooterStyle BackColor="Tan" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
SelectCommand="SELECT 訂單號碼,客戶編碼,員工編號,訂單日期 FROM dbo.訂貨主檔"></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="OrderDetailsPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" Caption="訂貨明細資料" CellPadding="3" DataKeyNames="訂單號碼,產品編號"
DataSourceID="SqlDataSource2" GridLines="Horizontal" Width="608px" AllowSorting="True">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<EmptyDataTemplate>
<b><i>請您從以上的清單中選取一筆訂單.....</i></b>
</EmptyDataTemplate>
<EmptyDataRowStyle BackColor="#404040" ForeColor="Red" />
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
SelectCommand="SELECT 訂單號碼,產品編號,單價,數量,折扣 FROM dbo.訂貨明細 WHERE (訂單號碼 = @OrderID)"
runat="server">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="OrderID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="Sorted" />
</Triggers>
</asp:UpdatePanel>