Newbie question : Connection between 3 or more webparts

Last post 12-14-2007 2:31 AM by Amanda Wang - MSFT. 1 replies.

Sort Posts:

  • Newbie question : Connection between 3 or more webparts

    12-10-2007, 11:10 AM
    • Member
      16 point Member
    • Stan92
    • Member since 10-31-2006, 4:53 PM
    • Posts 35

    Hi,

    I m trying to play with web parts.

    I would like to know if it's possible to create a connection between 3 web parts ?
    here's my web parts.
    WebPart A is a Gridview with the Customers list.
    WebPart B is a Gridview with the Orders list (the orders are filtered by the customer Id)
    WebPart C is a Gridview with the Details Order (and my goal is to display the detail of the order from the selection of B).

    how to make the relation between B and C. (for A->B, it works for me).

    Any help is really welcome.
    Stan

  • Re: Newbie question : Connection between 3 or more webparts

    12-14-2007, 2:31 AM
    Answer

    Hi,

    About the relation between the B and C should be similar to the relation between A and B.

    Below is my test code helps.

    1. Aspx code:

     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ParentId"
                                    DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                                    <Columns>
                                        <asp:BoundField DataField="ParentId" HeaderText="ParentId" SortExpression="ParentId" />
                                        <asp:BoundField DataField="ParentName" HeaderText="ParentName" SortExpression="ParentName" />
                                        <asp:CommandField ShowSelectButton="True" />
                                    </Columns>
                                </asp:GridView>
                                <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" DataKeyNames="SubID">
                                    <Columns>
                                        <asp:BoundField DataField="ParentId" HeaderText="ParentId" SortExpression="ParentId" />
                                        <asp:BoundField DataField="ChildName" HeaderText="ChildName" SortExpression="ChildName" />
                                        <asp:BoundField DataField="subID" HeaderText="subID" SortExpression="subID" />
                                        <asp:CommandField ShowSelectButton="True" />
                                    </Columns>
                                </asp:GridView>
                                <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" DataKeyNames="SubID">
                                    <Columns>
                                        <asp:BoundField DataField="SubID" HeaderText="SubID" SortExpression="SubID" />
                                        <asp:BoundField DataField="SubName" HeaderText="SubName" SortExpression="SubName" />
                                    </Columns>
                                </asp:GridView>

                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
                            SelectCommand="SELECT * FROM [ParentTable]"></asp:SqlDataSource>
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"  >
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" > 
                        </asp:SqlDataSource>

     2. The code behind:

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SqlDataSource2.SelectCommand = "SELECT * FROM [ChildTable] WHERE ([ParentId] = " + this.GridView1.SelectedDataKey.Value.ToString() + ")";
            this.GridView2.DataBind();
        }
        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
    this.SqlDataSource3.SelectCommand = "SELECT * FROM [SubTable] WHERE ([SubID] = "+this.GridView2.SelectedDataKey.Value.ToString()+")";
    this.GridView3.DataBind();

        }

     Notice, you should set the second gridview's datakey is the third gridview's key field.

     Hope it helps.

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)