I needed to insert the comments(0) tag at the bottom of each repeated row. The 0 part of the comments is based on a db query and is based on the blogid.

I realize I could have rewritten my SQL so that the comments was selected as a row and I would have continued with the repeater. But I wanted to be able to handled the binding and insert something myself. This is a common occurance and something that I would want to know how to do in the case it was absolutely necessary.

Here is what I ended up with ..

First I added a label in my repeaters itemtemplate and gave it a suitable name.

Then I added the following to the code behind page:


Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

Dim mylabel As Label
Dim sBlogid As String
Dim dRow As System.Data.Common.DbDataRecord

mylabel = CType(e.Item.FindControl(“lblComments”), Label)

dRow = CType(e.Item.DataItem, System.Data.Common.DbDataRecord)
sBlogid = dRow.Item(“blogid”)

Dim conn As New OleDbConnection
Dim comm As New OleDbCommand
Dim DR As OleDbDataReader
Dim strSQL As String

conn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.MapPath(“pathgoeshere”)
conn.Open()

strSQL = “select count(commentid) from comments where blogid = ” & sBlogid

comm.Connection = conn
comm.CommandText = strSQL

DR = comm.ExecuteReader()

DR.Read()
mylabel.Text = “Comments: (” & DR.Item(0) & “)”

DR.Close()
DR = Nothing
conn.Close()
comm.Dispose()
conn.Dispose()
comm = Nothing
conn = Nothing
End Sub

This gets the label object, retrieves the information from the row being bound and then gets the information from the database and updates the object within the repeater.