NestedDataGrid
.aspx
1<asp:datagrid id="grdCerSeted" Width="100%" Runat="server" CssClass="DataGrid" AutoGenerateColumns="False"
2 ShowHeader="False">
3 <Columns>
4<asp:TemplateColumn>
5 <HeaderStyle Width="0px"></HeaderStyle>
6 <ItemTemplate>
7 </td>
8 </tr>
9 <tr>
10 <td colspan="5">
11 <TABLE cellSpacing="3" cellPadding="3" width="100%" border="0">
12 <TR>
13 <TD>
14 <DIV id="divCertSetted" style="DISPLAY: inline" runat="server"><asp:datagrid id="drgSetedIntel" runat="server" Width="100%" AutoGenerateColumns="False">
15 <Columns>
16</Columns>
17 </asp:datagrid></DIV>
18 </TD>
19 </TR>
20 </TABLE>
21 </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid>
1<asp:datagrid id="grdCerSeted" Width="100%" Runat="server" CssClass="DataGrid" AutoGenerateColumns="False"
2 ShowHeader="False">
3 <Columns>
4<asp:TemplateColumn>
5 <HeaderStyle Width="0px"></HeaderStyle>
6 <ItemTemplate>
7 </td>
8 </tr>
9 <tr>
10 <td colspan="5">
11 <TABLE cellSpacing="3" cellPadding="3" width="100%" border="0">
12 <TR>
13 <TD>
14 <DIV id="divCertSetted" style="DISPLAY: inline" runat="server"><asp:datagrid id="drgSetedIntel" runat="server" Width="100%" AutoGenerateColumns="False">
15 <Columns>
16</Columns>
17 </asp:datagrid></DIV>
18 </TD>
19 </TR>
20 </TABLE>
21 </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid>
实现加减号合并展开效果
1function Toggle( commId, imageId )
2 {
3
4 var div = document.getElementById(commId);
5 var GetImg = document.getElementById(imageId);
6 if (document.all[commId].style.display == 'none')
7 {
8 document.all[commId].style.display = 'block';
9 document.all[imageId].src = '../Images/expand.gif';
10 }
11 else
12 {
13 document.all[commId].style.display = 'none';
14 document.all[imageId].src = '../Images/collapse.gif';
15 }
16 }
1function Toggle( commId, imageId )
2 {
3
4 var div = document.getElementById(commId);
5 var GetImg = document.getElementById(imageId);
6 if (document.all[commId].style.display == 'none')
7 {
8 document.all[commId].style.display = 'block';
9 document.all[imageId].src = '../Images/expand.gif';
10 }
11 else
12 {
13 document.all[commId].style.display = 'none';
14 document.all[imageId].src = '../Images/collapse.gif';
15 }
16 }
外面DataGrid的ItemCreated注册里面DataGrid事件
1private void grdCerSeted_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
2 {
3 ListItemType item = e.Item.ItemType;
4 if(item == ListItemType.Item || item == ListItemType.AlternatingItem)
5 {
6 //为包里面的DataGrid注册事件,只能手工注册,要不事件不会响应。
7 drgSetedIntel = (DataGrid)e.Item.FindControl("drgSetedIntel");
8 if(drgSetedIntel != null)
9 {
10 drgSetedIntel.ItemDataBound +=new DataGridItemEventHandler(drgSetedIntel_ItemDataBound);
11 drgSetedIntel.ItemCommand +=new DataGridCommandEventHandler(drgSetedIntel_ItemCommand);
12 drgSetedIntel.ItemCreated +=new DataGridItemEventHandler(drgSetedIntel_ItemCreated);
13 }
14 }
15 }
1private void grdCerSeted_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
2 {
3 ListItemType item = e.Item.ItemType;
4 if(item == ListItemType.Item || item == ListItemType.AlternatingItem)
5 {
6 //为包里面的DataGrid注册事件,只能手工注册,要不事件不会响应。
7 drgSetedIntel = (DataGrid)e.Item.FindControl("drgSetedIntel");
8 if(drgSetedIntel != null)
9 {
10 drgSetedIntel.ItemDataBound +=new DataGridItemEventHandler(drgSetedIntel_ItemDataBound);
11 drgSetedIntel.ItemCommand +=new DataGridCommandEventHandler(drgSetedIntel_ItemCommand);
12 drgSetedIntel.ItemCreated +=new DataGridItemEventHandler(drgSetedIntel_ItemCreated);
13 }
14 }
15 }
其它用法和正常DataGrid一样了。。。