Binding A Repeater Control Without A DataSource [ASP.NET]

The Control has to be one of the best controls has to offer. It’s flexible enough in it’s design to allow for significant markup customizations and yet shares the same simplicity of use as a GridView control. The only issue I have with the is it’s Databinding requirement. Though this isn’t even a significant issue as more times than not, any instance of repeating markup is for the express purpose of Databinding. However there are times when it would be nice to have the functionality of the without being constrained to bind it to a DataSource. Luckily for me, there is a work around that allows exactly this functionality.

By binding the repeater to a simple integer, used as a collection, you can exhort control over the amount of iterations and perform any binding logic during the repeater’s OnItemDataBound event.

For example:


Protected Sub BuildRepeatedMarkup()

' --- Determine How Many Grid Rows To Create --- |
Dim RowCount(3) As Integer

' This will force the repeater through 4 iterations: 0,1,2,3 --- |
MyRepeater.DataSource = RowCount
MyRepeater.DataBind()

End Sub

Protected Sub MyRepeater_OnitemDataBound(ByVal Sender as Object, ByVal e As RepeaterItemEventArgs)

'--- Any and all logic can live here --- |

End Sub

Handy.