1: <asp:GridView ID="gvMaster" runat="server"
2: AllowPaging="True"
3: AutoGenerateColumns="False"
4: DataKeyNames="CustomerID"
5: DataSourceID="SqlDataSource1"
6: onrowdatabound="gvMaster_RowDataBound">
7: <Columns>
8: <asp:TemplateField>
9: <ItemTemplate>
10: <a href="javascript:collapseExpand('customerID-
11: <%# Eval("CustomerID") %>');">
12: <img id="imagecustomerID-<%# Eval("CustomerID") %>"
13: alt="Click to show/hide orders"
14: border="0" src="plus.png" /></a>
15: </ItemTemplate>
16: </asp:TemplateField>
17: <asp:BoundField DataField="CustomerID"
18: HeaderText="CustomerID"/>
19: <asp:BoundField DataField="CompanyName"
20: HeaderText="CompanyName"/>
21:
22: <asp:TemplateField>
23: <ItemTemplate>
24: <tr><td colspan="100%">
25: <div id="customerID-<%# Eval("CustomerID") %>"
26: style="display:none;
27: position:relative;left:25px;">
28:
29: <asp:GridView ID="nestedGridView" runat="server"
30: AutoGenerateColumns="False"
31: DataKeyNames="OrderID">
32: <Columns>
33: <asp:BoundField DataField="OrderID" HeaderText="OrderID"/>
34: <asp:BoundField DataField="OrderDate" HeaderText="OrderDate"/>
35: <asp:BoundField DataField="Freight" HeaderText="Freight"/>
36: </Columns>
37: </asp:GridView>
38: </div>
39: </td></tr>
40: </ItemTemplate>
41: </asp:TemplateField>
42: </Columns>
43: </asp:GridView>
44:
45: <asp:SqlDataSource ID="SqlDataSource1" runat="server"
46: ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
47: SelectCommand="SELECT [CustomerID], [CompanyName]
48: FROM [Customers]">
49: </asp:SqlDataSource>