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

row.FindControl(

"DefinitionRepeater").Visible = False

Next

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

myRepeater.Visible =

True

End Sub

The markup part (nest repeater inside a Gridview)

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

DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_OnSelectedIndexChanged">

<Columns>

<asp:CommandField ShowSelectButton="True" />

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

SortExpression="countryid" />

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

<ItemTemplate>

<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">

<HeaderTemplate>

</HeaderTemplate>

<ItemTemplate>

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

<br /><br />

</ItemTemplate>

<FooterTemplate>

</FooterTemplate>

</asp:Repeater>

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

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

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

<SelectParameters>

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

</asp:SqlDataSource>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

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

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

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

</asp:SqlDataSource>

Advertisements


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s