Here I have created sample that will help you out.
HTML
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("div.accordian").accordion({
collapsible: true,
active: false,
autoHeight: false
});
});
</script>
<div class="accordian">
<asp:Repeater ID="rptAccordian" runat="server" OnItemDataBound="OnItemDataBound">
<ItemTemplate>
<h3>
<a class="" href="#">
<%# Eval("Title") %></a></h3>
<div class="accordian">
<asp:Repeater ID="rptSubAccordian" runat="server">
<ItemTemplate>
<h3>
<a class="" href="#">
<%#Eval("Content") %></a></h3>
<div>
<%#Eval("ContentElement") %>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:HiddenField ID="hfTitle" runat="server" Value=' <%# Eval("Title") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
C#
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Title"), new DataColumn("Content"), new DataColumn("ContentElement") });
dt.Rows.Add("Section 1", "This is content of Section 1.1", "<p>Element of Section 1.1</p>");
dt.Rows.Add("Section 1", "This is content of Section 1.2", "<p>Element of Section 1.2</p>");
dt.Rows.Add("Section 2", "This is content of Section 2.1", "<p>Element of Section 2.1</p>");
dt.Rows.Add("Section 2", "This is content of Section 2.2", "<p>Element of Section 2.2</p>");
dt.Rows.Add("Section 3", "This is content of Section 3.1", "<p>Element of Section 3.1</p>");
dt.Rows.Add("Section 3", "This is content of Section 3.2", "<p>Element of Section 3.2</p>");
dt.Rows.Add("Section 4", "This is content of Section 4.1", "<p>Element of Section 4.1</p>");
dt.Rows.Add("Section 4", "This is content of Section 4.2", "<p>Element of Section 4.2</p>");
DataView dv = new DataView(dt);
DataTable distinctTitle = dv.ToTable(true, "Title");
rptAccordian.DataSource = distinctTitle;
rptAccordian.DataBind();
}
}
protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string Title = ((HiddenField)e.Item.FindControl("hfTitle")).Value;
var subSection = from data in dt.AsEnumerable()
where data["Title"].Equals(Title)
select data;
Repeater rptSubAccordian = (Repeater)e.Item.FindControl("rptSubAccordian");
rptSubAccordian.DataSource = subSection.CopyToDataTable();
rptSubAccordian.DataBind();
}
}
VB
Private dt As New DataTable()
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Me.IsPostBack Then
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Title"), New DataColumn("Content"), New DataColumn("ContentElement")})
dt.Rows.Add("Section 1", "This is content of Section 1.1", "<p>Element of Section 1.1</p>")
dt.Rows.Add("Section 1", "This is content of Section 1.2", "<p>Element of Section 1.2</p>")
dt.Rows.Add("Section 2", "This is content of Section 2.1", "<p>Element of Section 2.1</p>")
dt.Rows.Add("Section 2", "This is content of Section 2.2", "<p>Element of Section 2.2</p>")
dt.Rows.Add("Section 3", "This is content of Section 3.1", "<p>Element of Section 3.1</p>")
dt.Rows.Add("Section 3", "This is content of Section 3.2", "<p>Element of Section 3.2</p>")
dt.Rows.Add("Section 4", "This is content of Section 4.1", "<p>Element of Section 4.1</p>")
dt.Rows.Add("Section 4", "This is content of Section 4.2", "<p>Element of Section 4.2</p>")
Dim dv As New DataView(dt)
Dim distinctTitle As DataTable = dv.ToTable(True, "Title")
rptAccordian.DataSource = distinctTitle
rptAccordian.DataBind()
End If
End Sub
Protected Sub OnItemDataBound(sender As Object, e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim Title As String = DirectCast(e.Item.FindControl("hfTitle"), HiddenField).Value
Dim subSection = From data In dt.AsEnumerable() Where data("Title").Equals(Title)data
Dim rptSubAccordian As Repeater = DirectCast(e.Item.FindControl("rptSubAccordian"), Repeater)
rptSubAccordian.DataSource = subSection.CopyToDataTable()
rptSubAccordian.DataBind()
End If
End Sub
Screenshot
