数据绑定 Repeater 控件中的每个复选框列表 (asp.net 4)
在这里问了我的最后一个问题_ 创建具有 SP 返回的不同标题的动态框 (div)
我创建了一个中继器控件并创建了几个框(div)。我可以成功地为每个盒子创建标题。我的下一个重要步骤是在转发器控件中添加复选框列表。这些复选框列表由存储过程返回的数据填充。我有大约 8 个盒子,但这个数字取决于存储过程返回的数据。使用我现在拥有的代码,所有复选框列表将显示相同的数据。我需要为每个类别设置不同的复选框列表。我的下一步将是创建 SelectedIndexChanged 事件并重新过滤所有这些复选框列表。整体设计和理念有点像我们在购物车上找到的搜索过滤器。我发现有人说中继器只适合显示数据,所以我可能必须使用其他东西。我无法集思广益如何实现这一目标。我必须使用VB.net。数据库是SQL server 2008。数据源使用Linq就可以了。请给我建议如何实现这一目标。还请建议实现此目的的最佳控制。我不需要坚持中继器控制。
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound" >
<ItemTemplate>
<div class="portlet">
<div class="portlet-header"> <%# Eval("categoryLabel") %></div>
<div class="portlet-content">
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
</div></div>
</ItemTemplate>
</asp:Repeater>
Protected Sub Repeater1_OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
Dim x As New SIDLinqDataContext
Dim item As RepeaterItem = e.Item
Dim query = x.GetSelectedValue(xxxx, xxxx)
Dim cbl1 As CheckBoxList = DirectCast(item.FindControl("checkboxlist1"), CheckBoxList)
For Each aa In query
cbl1.items.add(New ListItem(xxxx, xxxx))
Next
End Sub
OnLoad page event
Dim dc As New SIDLinqDataContext
Dim query = dc.GetCategories(1710307, 9)
Repeater1.DataSource = query
Repeater1.DataBind()
Having asked my last question here _
Creating dynamic boxes (divs) with different titles returned by SP
I created a repeater control and create few boxes (divs). I could successfully create Titles for each boxes. My next big step is to have Checkboxlists in the repeater control. Those checkboxlists are populated by data returned by a stored procedure. I have about 8 boxes but this number vary depend on the data returned by the Stored Procedure. With the code i have now, all the checkboxlist will display the same data. I need to have different checkboxlist for each category. My next step will be to create SelectedIndexChanged Events and refilter all those checkboxlist. The overall design and idea is sort of like Search Filter that we find on shopping carts. I found some say Repeater are just good to display data so may be i have to use something else. I can't brainstorm how this can be achievable. I have to use VB.net. The database is SQL server 2008. Using Linq for datasource is alright. Please give me suggestion how this can be achieveable. Please also suggest best control to achieve this. I don't need to stick to repeater control.
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound" >
<ItemTemplate>
<div class="portlet">
<div class="portlet-header"> <%# Eval("categoryLabel") %></div>
<div class="portlet-content">
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
</div></div>
</ItemTemplate>
</asp:Repeater>
Protected Sub Repeater1_OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
Dim x As New SIDLinqDataContext
Dim item As RepeaterItem = e.Item
Dim query = x.GetSelectedValue(xxxx, xxxx)
Dim cbl1 As CheckBoxList = DirectCast(item.FindControl("checkboxlist1"), CheckBoxList)
For Each aa In query
cbl1.items.add(New ListItem(xxxx, xxxx))
Next
End Sub
OnLoad page event
Dim dc As New SIDLinqDataContext
Dim query = dc.GetCategories(1710307, 9)
Repeater1.DataSource = query
Repeater1.DataBind()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论