HTML
<asp:Repeater ID="rptParent" runat="server" OnItemDataBound="rptParent_OnItemDataBound">
<ItemTemplate>
<asp:Label ID="lblProductAbbr" Text='<%# Eval("Abbr") %>' runat="server" />
<asp:Repeater ID="rptChild" runat="server">
<ItemTemplate>
<table>
<tr>
<td align="left">
<asp:Label ID="lblProductAbbr" Text='<%# Eval("ProductName") %>' runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Namesapace
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Populate("SELECT DISTINCT SUBSTRING(ProductName,1,1) AS Abbr FROM dbo.Products", this.rptParent);
}
}
protected void rptParent_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpt = e.Item.FindControl("rptChild") as Repeater;
Populate(string.Format("SELECT DISTINCT ProductName FROM dbo.Products WHERE ProductName LIKE '{0}%'", (e.Item.FindControl("lblProductAbbr") as Label).Text), rpt);
}
}
private void Populate(string query, Repeater rpt)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection _cn = new SqlConnection(constr))
{
using (SqlCommand _cmd = new SqlCommand(query, _cn))
{
using (SqlDataAdapter da = new SqlDataAdapter(_cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
rpt.DataSource = ds;
rpt.DataBind();
}
}
}
}
Screenshot