这是一个手风琴的样品,但是你可以用其他的东西:
Markup:
<ajax:Accordion ID="Accordion1" runat="Server"
SelectedIndex="0"
HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent"
AutoSize="None" FadeTransitions="true"
TransitionDuration="250" FramesPerSecond="40"
RequireOpenedPane="false" SuppressHeaderPostbacks="true">
<HeaderTemplate><%# Eval("Key")%></HeaderTemplate>
<ContentTemplate>
<asp:ListView runat="server" ID="MyListView" DataSource='<%# Eval("Values") %>'>
<LayoutTemplate>
<table style="width:75%">
<tr>
<th>Code</th>
<th>Total</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("Code")%></td>
<td><%# Eval("Total")%></td>
</tr>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</ajax:Accordion>
代码落后:
public class Company
{
public string CompanyName;
public int Code, Total;
public Company(string company, int code, int total)
{
this.CompanyName = company; this.Code = code;
this.Total = total;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var Companies = new Company[] {
new Company("One", 1, 10),
new Company("Two", 1, 5),
new Company("Two", 2, 8)
};
Accordion1.DataSource = Companies
.GroupBy(c => c.CompanyName, c => new { Code = c.Code, Total = c.Total },
(k, enumerable) => new { Key = k, Values = enumerable });
Accordion1.DataBind();
}
}