How to access a repeater, drop-down list, ListItem and AlternatingListItem using a select case scenario


This function illustrates how to refer to a repeater in .NET and loop thru the Items while using a Case Statement. In this particular function a dicionary stores the desired values and is returned.

 

Protected Function getWeekdaysForDBEntry() As Dictionary(Of Integer, DateTime)

Dim theWeekdays As New Dictionary(Of Integer, DateTime)
For Each ri As RepeaterItem In RepeaterWeekday.Items

Select Case ri.ItemType

Case ListItemType.Item, ListItemType.AlternatingItem

Dim label_stops As Label = DirectCast(ri.FindControl("lblStop"), Label)
Dim ddl_Weekday As DropDownList = DirectCast(ri.FindControl("ddl_Weekday"), DropDownList)
Dim theStop As Integer = CType(label_stops.Text, Integer)
Dim theSelectedWeekday As DateTime = ddl_Weekday.SelectedValue
Dim result() As DataRow = TripInfo.Select("Stop = " & theStop)

For Each row As DataRow In result

'comparing the useDate

If row.Item(9) <> theSelectedWeekday Then

theWeekdays.Add(theStop, theSelectedWeekday)

End If

Next

Exit Select

End Select

Next

Return theWeekdays

End Function

 

'The front code of the repeater

<asp:Repeater ID="RepeaterWeekday" runat="server" OnItemDataBound="RepeaterWeekday_ItemDataBound" >

<ItemTemplate>

<asp:Panel ID="pnlrepeater" runat="server" class="colored_lightgreen" style="height:90px; padding:10px;">

<asp:Label ID="lblDel" runat="server" Text='<%# Eval("DateDelivered")%>' Visible="False"></asp:Label>
<p>
<h5>
<asp:Label runat="server" Text="Stop: " ForeColor="Black"></asp:Label>
<asp:Label ID="lblStop" runat="server" Text='<%# Eval("Stop")%>' ForeColor="Black"></asp:Label>
&nbsp;&nbsp;
<asp:Label ID="Label2" runat="server" Text='<%# " " & Eval("ShippingAddress")%>'></asp:Label>
<!--hidden input-->
<asp:Label ID="lbl_transferred" runat="server" Text='<%# Eval("ReasonCode")%>' visible="false"></asp:Label>
</h5>
<asp:DropDownList ID="ddl_Weekday" runat="server" AppendDataBoundItems="true" Font-Italic="True" ForeColor="#993300" class="form-control">
</asp:DropDownList>&nbsp;&nbsp;
</p>
</asp:Panel>

</ItemTemplate>

</asp:Repeater>

Tags: repeater, select case
Last update:
2014-09-15 20:19
Author:
Mark
Revision:
1.1
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags