![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
<
asp:Accordion ID
=
"
adTree
"
AutoSize
=
"
None
"
runat
=
"
server
"
HeaderCssClass
=
"
bgs type typetop
"
2 FadeTransitions = " True " FramesPerSecond = " 45 " Width = " 182px "
3 RequireOpenedPane = " False " >
4 </ asp:Accordion >
2 FadeTransitions = " True " FramesPerSecond = " 45 " Width = " 182px "
3 RequireOpenedPane = " False " >
4 </ asp:Accordion >
后台代码:
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
protected
void
Page_Load(
object
sender, EventArgs e)
2 {
3 if ( ! Page.IsPostBack)
4 {
5 BindTree();
6 }
7 }
8
9 private void BindTree()
10 {
11 SqlDataReader sdr = md.GetNewsClass();
12 while (sdr.Read())
13 {
14 AccordionPane ap = new AccordionPane();
15 Table tab = new Table();
16 tab.CellPadding = 0 ;
17 tab.CellSpacing = 0 ;
18 tab.BorderWidth = Unit.Pixel( 0 );
19 tab.Height = Unit.Pixel( 25 );
20 TableRow tr = new TableRow();
21 TableCell td = new TableCell();
22 td.Text = sdr[ "Class Name " ].ToString();
23 td.CssClass = " tops " ;
24 tr.Cells.Add(td);
25 tab.Rows.Add(tr);
26 ap.HeaderContainer.ID = " D " + sdr[ " ID " ].ToString();
27 ap.HeaderCssClass = " bgs " ;
28 ap.HeaderContainer.Width = Unit.Pixel( 182 );
29 ap.HeaderContainer.Controls.Add(tab);
30
31 int id = Convert.ToInt32(sdr[ " ID " ].ToString());
32 SqlDataReader sdr1 = mwt.GetNewsTitle(id);
33 while (sdr1.Read())
34 {
35 Table tabs = new Table();
36 tabs.CellPadding = 0 ;
37 tabs.CellSpacing = 0 ;
38 tabs.BorderWidth = Unit.Pixel( 0 );
39 TableRow trs = new TableRow();
40 TableCell tds = new TableCell();
41 tabs.CssClass = " MM " ;
42 tds.Text = " <a target='_blank' href=ShowNews.aspx?ID= " + sdr1[ " ID " ].ToString() + " > " + sdr1[ "Title " ].ToString() + " </a> " ;
43 trs.Cells.Add(tds);
44 tabs.Rows.Add(trs);
45 ap.ContentContainer.Width = Unit.Pixel( 182 );
46 ap.ContentContainer.ID = " CC " + sdr1[ " ID " ].ToString();
47 ap.ContentContainer.CssClass = " CC " ;
48 ap.ContentContainer.Controls.Add(tabs);
49 }
50 sdr1.Close();
51 adTree.Panes.Add(ap);
52 }
53 sdr.Close();
54 }
2 {
3 if ( ! Page.IsPostBack)
4 {
5 BindTree();
6 }
7 }
8
9 private void BindTree()
10 {
11 SqlDataReader sdr = md.GetNewsClass();
12 while (sdr.Read())
13 {
14 AccordionPane ap = new AccordionPane();
15 Table tab = new Table();
16 tab.CellPadding = 0 ;
17 tab.CellSpacing = 0 ;
18 tab.BorderWidth = Unit.Pixel( 0 );
19 tab.Height = Unit.Pixel( 25 );
20 TableRow tr = new TableRow();
21 TableCell td = new TableCell();
22 td.Text = sdr[ "Class Name " ].ToString();
23 td.CssClass = " tops " ;
24 tr.Cells.Add(td);
25 tab.Rows.Add(tr);
26 ap.HeaderContainer.ID = " D " + sdr[ " ID " ].ToString();
27 ap.HeaderCssClass = " bgs " ;
28 ap.HeaderContainer.Width = Unit.Pixel( 182 );
29 ap.HeaderContainer.Controls.Add(tab);
30
31 int id = Convert.ToInt32(sdr[ " ID " ].ToString());
32 SqlDataReader sdr1 = mwt.GetNewsTitle(id);
33 while (sdr1.Read())
34 {
35 Table tabs = new Table();
36 tabs.CellPadding = 0 ;
37 tabs.CellSpacing = 0 ;
38 tabs.BorderWidth = Unit.Pixel( 0 );
39 TableRow trs = new TableRow();
40 TableCell tds = new TableCell();
41 tabs.CssClass = " MM " ;
42 tds.Text = " <a target='_blank' href=ShowNews.aspx?ID= " + sdr1[ " ID " ].ToString() + " > " + sdr1[ "Title " ].ToString() + " </a> " ;
43 trs.Cells.Add(tds);
44 tabs.Rows.Add(trs);
45 ap.ContentContainer.Width = Unit.Pixel( 182 );
46 ap.ContentContainer.ID = " CC " + sdr1[ " ID " ].ToString();
47 ap.ContentContainer.CssClass = " CC " ;
48 ap.ContentContainer.Controls.Add(tabs);
49 }
50 sdr1.Close();
51 adTree.Panes.Add(ap);
52 }
53 sdr.Close();
54 }