asp.net ajax技巧2

  下面是异步的一对多流程,有两个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>

你可能感兴趣的:(.net,Ajax,asp.net,asp)