Show nested Repeater inside a Gridview on Selection

Here is a way to show a nested repeater inside a Gridview.

Protected Sub GridView1_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

For Each row As GridViewRow In GridView1.Rows


"DefinitionRepeater").Visible = False


Dim myRepeater As Repeater = DirectCast(GridView1.SelectedRow.FindControl("DefinitionRepeater"), Repeater)

myRepeater.Visible =


End Sub

The markup part (nest repeater inside a Gridview)

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_OnSelectedIndexChanged">


<asp:CommandField ShowSelectButton="True" />

<asp:BoundField DataField="countryid" HeaderText="countryid"

SortExpression="countryid" />

<asp:TemplateField HeaderText="CountryName" SortExpression="CountryName">


<asp:Label ID="Label1" runat="server" Text=’<%# Eval("CountryName") %>‘></asp:Label>

<asp:Label ID="lblcountryid" runat="server" Text=’<%# Eval("countryid") %> Visible="false"></asp:Label></div>

<asp:Repeater ID="DefinitionRepeater" runat="server" DataSourceID="SqlDataSource2" Visible="false">




<b><%# "&nbsp;&nbsp;&nbsp;&nbsp;" + Eval("cityname")%></b>

<br /><br />





<asp:SqlDataSource ID="SqlDataSource2" runat="server"

ConnectionString="<%$ ConnectionStrings:test_for_forumConnectionString %>"

SelectCommand="SELECT cityid, cityname, description FROM [Table2] WHERE [countryid]=@countryid">


<asp:ControlParameter ControlID="lblcountryid" Name="countryid" /></SelectParameters>






<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:test_for_forumConnectionString %>"

SelectCommand="SELECT [countryid], [CountryName] FROM [Table1]">



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s