這很可能,但我會使用ListView或DataList作爲父容器。這給一個鏡頭:
<table width="595px">
<asp:DataList BackColor="#ffffff" id="DataList1" DataKeyField="<ID>" OnItemDataBound="DataList1_ItemDataBound" runat="server" Width="100%">
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" Text="+" OnCommand="LinkButton1_Command" CommandArgument='<%#Container.ItemIndex%>'></asp:LinkButton>
</td>
<td><%#Eval("<COLUMN NAME>")%></td>
<td><%#Eval("<COLUMN NAME>")%></td>
<td><%#Eval("<COLUMN NAME>")%></td>
</tr>
<asp:Panel ID="pnlChildView" runat="server">
<asp:DataList ID="DataList2" runat="server" Width="100%">
<ItemTemplate>
<tr>
<td><%#Eval("<CHILD OLUMN NAME>")%></td>
<td><%#Eval("<CHILD COLUMN NAME>")%></</td>
<td><%#Eval("<CHILD COLUMN NAME>")%></</td>
</tr>
</ItemTemplate>
</asp:DataList>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
</table>
而當用戶點擊的LinkButton /按鈕在DataList1,做這樣的事情:
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
//pass index of item in command argument
int itemIndex = Convert.ToInt32(e.CommandArgument);
//find the pnlChildView control
Panel childViewPanel = (Panel)DataList1.Items[itemIndex].FindControl("pnlChildView");
if (childViewPanel != null)
{
//toggle visibility of childViewPanel and bind child list if panel is visible
if (childViewPanel.Visible)
{
DataList childList = childViewPanel.FindControl("DataList2");
if (childList != null)
{
int keyValue = (int)DataList1.DataKeys[itemIndex];
//bind the list using DataList1 data key value
childList.DataSource = <DATA SOURCE>; //get data using keyValue
childList.DataBind();
}
}
}
}