.NET Repeaters Cheat Sheet (vb)
create the repeater
<ItemTemplate>
<asp:Label ID="lblQuestion" runat="server"></asp:Label>
<asp:Label ID="lblQID" visible="false" runat="server"></asp:Label>
<br />
<asp:RadioButtonList ID="answer" runat="server"Â >
<asp:ListItem Text="True" Value="T" ></asp:ListItem>
<asp:ListItem  Text="False" Value="F"></asp:ListItem>
</asp:RadioButtonList>
<hr />
</ItemTemplate>
</asp:Repeater>
back end code:
databind the repeater itself
If Not Page.IsPostBack Then
rpPostTest.DataSource = objTraining.getRandomQuestions()
rpPostTest.DataBind()
End If
End Sub
databind object inside a repeater with appropriate values
If (e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem) Then
‘fill in the drop down list
Dim item As RepeaterItem = e.Item
Dim drv As System.Data.DataRowView = DirectCast((e.Item.DataItem), System.Data.DataRowView)
Dim strQuestion As String = drv.Row("question").ToString()
Dim strID As String = drv.Row("id").ToString()
Dim l As Label = DirectCast(item.FindControl("lblQuestion"), Label)
l.Text = strQuestion
Dim l2 As Label = DirectCast(item.FindControl("lblQID"), Label)
l2.Text = strID
End If
End Sub
now… to access objects inside a repeater with an external control:
Dim correct As Integer = 0
Dim wrong As Integer = 0
Dim userid As Integer = Session("userID")
For Each repeaterItem As RepeaterItem In rpPostTest.Items
Dim l As Label = DirectCast(repeaterItem.FindControl("lblQID"), Label)
Dim d As RadioButtonList = DirectCast(repeaterItem.FindControl("answer"), RadioButtonList)
Dim dd As DropDownList = DirectCast(repeaterItem.FindControl("ddlAnswer"), DropDownList)
<span style="color: #000000;">//calculations and updates go here
</span>
Next
End Sub
to catch the selectedIndexChange of the dropdownlist
refer here: