S
Stephen Miller
What is the best method to add a row counter to a Repeater control? If
for example, I assigned a DataView to a Repeater in the code behind
like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Repeater1.DataSource = CreateDataSource()
Repeater1.DataBind()
End Sub
Function CreateDataSource() As ICollection
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add(New DataColumn("myValue", GetType(String)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(1) = "Item " + i.ToString()
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function
I was hoping to declare an inline variable and increment for each
iteration of the ItemTemplate, ie:
<%
Dim lngRow As Long = -1
%>
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%
lngRow += 1
%>
<%# lngRow & "-" & DataBinder.Eval(Container.DataItem, "myValue")
%><br>
</ItemTemplate>
</asp:Repeater>
.... but, it doesn't consider lngRow to be a global variable and errors
when I attempt to increment.
Without altering the DataSource (and yes, I know my sample code
already has a counter), what is the best way to add a counter?
Thanks,
Stephen
for example, I assigned a DataView to a Repeater in the code behind
like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Repeater1.DataSource = CreateDataSource()
Repeater1.DataBind()
End Sub
Function CreateDataSource() As ICollection
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add(New DataColumn("myValue", GetType(String)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(1) = "Item " + i.ToString()
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function
I was hoping to declare an inline variable and increment for each
iteration of the ItemTemplate, ie:
<%
Dim lngRow As Long = -1
%>
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%
lngRow += 1
%>
<%# lngRow & "-" & DataBinder.Eval(Container.DataItem, "myValue")
%><br>
</ItemTemplate>
</asp:Repeater>
.... but, it doesn't consider lngRow to be a global variable and errors
when I attempt to increment.
Without altering the DataSource (and yes, I know my sample code
already has a counter), what is the best way to add a counter?
Thanks,
Stephen