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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.