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.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Yours sincerely,
Amanda Wang
Microsoft Online Community Support