R – Nested Gridview in Repeater control

asp.netgridviewnestedrepeater

I have a gridview control nested within a repeater control.


The repeater control is databound on pageload and in the itemdatabound event
I look for the gridview control

If e.Item.ItemType = ListItemType.Item Then
Dim gvw As GridView = DirectCast(e.Item.Controls(3), GridView)
gvw.DataSource = GetData()
gvw.DataBind()
End If

After all this happens my page is displaying the repeater controls data
and data in the gridview but the problem is only alternate gridviews have data
i.e. row 1, 3, 5… in repeater control has grid that is databound
but rows 2, 4, 6… does not display data

markup is – just an example

<repeater>
<itemtemplate>
<table>
<tr>
<td>
<gridview />
</td>
</tr>
<tr>
<td>
<label Text='<%# Eval("some_data") %>'
</td>
</tr>
</table>
</itemtemplate>
</repeater>

again the above markup is just an example and it is complete

I think I'm doing something seriously wrong.

Best Answer

In your code

If e.Item.ItemType = ListItemType.Item Then Dim gvw As GridView = DirectCast(e.Item.Controls(3), GridView) gvw.DataSource = GetData() gvw.DataBind() End If

you should add an "OR" clause to check if the ItemType is an AlternateItem as well

If e.Item.ItemType = ListItemType.Item OR e.Item.ItemType = ListItemType.AlternateItem Then Dim gvw As GridView = DirectCast(e.Item.Controls(3), GridView) gvw.DataSource = GetData() gvw.DataBind() End If
Related Topic