Question

I'm trying to create a repeater control bound with data of my database. This should be use with a BLL. But I don't know what I have to do.

I hope someone can help me with this..

The code I used in the page.aspx.vb is:

Public Function showRepeater()
    Try
        ' 1 - BLL
        Dim BLLVragenRepeater As New VraagBLL

        ' 2 - Getting all topics
        Dim alleVragenRepeater As Dataset.tblVragenDataTable
        alleVragenRepeater = BLLVragenRepeater.getVraagByTopicId(5)

        ' 3 - creating repeater and binding with data
        Dim rptRepeater As Repeater = Nothing
        rptRepeater.DataSource = BLLVragenRepeater.getVraagByTopicId(5)
        rptRepeater.DataBind()

        ' 4 - show repeater in placeholder
        plcRepeater.Controls.Add(rptRepeater)
    Catch ex As Exception
        lblFeedback.Text = ex.Message
    End Try
End Function

The code I used in the page.aspx is:

<asp:PlaceHolder ID="plcRepeater" runat="server">
   <asp:Repeater ID="rptRepeater" runat="server">
     <ItemTemplate>
       <ul>
         <li></li>
       </ul>
     </ItemTemplate>
   </asp:Repeater>
 </asp:PlaceHolder>
Was it helpful?

Solution

You need to reference your DataFields in the ItemTemplate using the DataBinder.Eval Method.
Something like...

            <ItemTemplate>      
                <ul>      
                    <li><% DataBinder.Eval(rpt.DataSource, "FieldName")%></li>      
                </ul>      
            </ItemTemplate> 

OTHER TIPS

You are overwriting your repeater with a null reference:

Dim rptRepeater As Repeater = Nothing

You shouldn't do that - remove that line and things should work as expected.

Additionally, you should be binding a collection to the repeater and use data binding expressions in order to display data in the repeater itself.

Without knowing more about your data model, I can't give you a better answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top