使用 BLL 创建中继器
我正在尝试创建一个与数据库数据绑定的转发器控件。 这应该与 BLL 一起使用。 但我不知道我必须做什么。
我希望有人可以帮助我。
我在 page.aspx.vb 中使用的代码是:
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
我在 page.aspx 中使用的代码是:
<asp:PlaceHolder ID="plcRepeater" runat="server">
<asp:Repeater ID="rptRepeater" runat="server">
<ItemTemplate>
<ul>
<li></li>
</ul>
</ItemTemplate>
</asp:Repeater>
</asp:PlaceHolder>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用 引用 ItemTemplate 中的 DataFields DataBinder.Eval方法.
类似...
You need to reference your DataFields in the ItemTemplate using the DataBinder.Eval Method.
Something like...
您正在用空引用覆盖您的转发器:
您不应该这样做 - 删除该行,事情应该按预期工作。
此外,您应该将集合绑定到转发器并使用数据绑定表达式以便在转发器本身中显示数据。
如果不了解您的数据模型的更多信息,我无法给您更好的答案。
You are overwriting your repeater with a null reference:
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.