开发者

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 开发者_JS百科ID="plcRepeater" runat="server">
   <asp:Repeater ID="rptRepeater" runat="server">
     <ItemTemplate>
       <ul>
         <li></li>
       </ul>
     </ItemTemplate>
   </asp:Repeater>
 </asp:PlaceHolder>


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> 


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜