Search code examples
asp.netdatabaserepeaterbll

Creating a repeater using BLL


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>

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>