I have a Repeater on my page. There's nothing spectacular about it.
<asp:Repeater runat="server" ID="rptBusiness">
<HeaderTemplate>
<table>
<colgroup>
<col width="170px" />
<col width="75px" />
<col width="75px" />
</colgroup>
<tr>
<th style="text-align:left; background-color: Silver;">Business</th>
<th style="text-align:left; background-color: Silver;">Rep</th>
<th style="text-align:left; background-color: Silver;">City</th>
</tr>
</table>
<div class="scrollDiv">
<table>
<colgroup>
<col width="155px" />
<col width="75px" />
<col width="75px" />
</colgroup>
</HeaderTemplate>
<ItemTemplate>
<asp:Literal runat="server" ID="litRow" />
</ItemTemplate>
<FooterTemplate>
</table>
</div>
</FooterTemplate>
</asp:Repeater>
- The HeaderTemplate defines a table to contain the header rows, which don't scroll. It also defines the start of the content table, which is contained in a scrolling div.
- The ItemTemplate contains a single Literal control, which I fill in the codebehind with table rows (we'll get to that in a moment).
- The FooterTemplate closes the scrolling div and the table.
Note, there's nothing wrong with the layout. It's the databinding. In the codebehind, I have the following code:
Dim list As System.Collections.Generic.List(Of Business)
list = BusinessWithAddress.Select(excludeBusKey, _
searchCriteria, _
contained, _
Connector.GetConnectionString())
Me.rptBusiness.DataSource = list
Me.rptBusiness.DataBind()
Now, I can see that list contains many distinct businesses. Over 800 of them, in fact. The problem is that when the ItemCreated event fires, I get the same business item every single time.
Why?
Edit:
Forgot. This is how I inspect the item to determine it's the same item over and over again.
Private Sub rptBusiness_ItemCreated(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) _
Handles rptBusiness.ItemCreated
Dim item = CType(e.Item.DataItem, Business)
' Content elided
End Sub