我想做一个嵌套的中继器控制与复选框里面。基本上,我想是 分类喜欢的复选框,与复选框列表使用asp.net嵌套中继器
Group 1
Item 1
Item 2
Group 2
Item 3
Item 4
Group 3
Item 5
Item 6
我面临的问题是,我得到的错误:
错误1:“DataRowView的”未声明。由于其保护级别,它可能无法访问。
错误2:名称'DataRowView'未声明。
ASPX:
<asp:Repeater ID="rp_Groups" runat="server" OnItemDataBound="rp_Groups_ItemDataBound" >
<ItemTemplate>
<ul>
<asp:CheckBox runat="server" ID="chk_Group" Text='<%# Eval("category_type") %>' Value='<%# Eval("service_type_category_id") %>' onclick="OnGroupClick" />
<p class="nested">
<asp:CheckBoxList runat="server" ID="chk_Items" DataValueField="ServiceTypeID" DataTextField="Name"
DataSource='<%# ((DataRowView)Container.DataItem).CreateChildView("FK_esnServiceType_Service_Type_Categorization") %>' ></asp:CheckBoxList>
</p>
</ul>
</ItemTemplate>
</asp:Repeater>
代码隐藏:
Public Sub Fill()
Dim dtServiceCategory As DataTable = ServiceTypeModel.GetService_Categories()
Dim dtServiceType As DataTable = ServiceTypeModel.Search("", True)
rp_Groups.DataSource = dtServiceCategory
rp_Groups.DataBind()
Dim ds As New DataSet()
ds.Tables.Add(dtServiceCategory)
ds.Tables.Add(dtServiceType)
Dim relation As New DataRelation("FK_esnServiceType_Service_Type_Categorization", ds.Tables("dtServiceCategory").Columns("service_type_category_id"), ds.Tables("dtServiceType").Columns("CategorizationID"), False)
ds.Relations.Add(relation)
relation.Nested = True
End Sub
Protected Sub rp_Groups_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rp_Groups.ItemDataBound
Dim chklist As CheckBoxList = DirectCast(e.Item.FindControl("chk_Items"), CheckBoxList)
If chklist IsNot Nothing Then
chklist.DataSource = DirectCast(e.Item.DataItem, DataRowView).CreateChildView("FK_esnServiceType_Service_Type_Categorization")
chklist.DataBind()
End If
End Sub
我在想什么?
我尝试了你的想法,并得到错误:'DataRowView'是'数据'中的一种类型,不能用作表达式。 \t当我删除checkboxlist的数据源时,我没有收到任何错误! – Anuya 2013-04-04 09:07:26
@Anuya你是否尝试过我在编辑中建议的内容? – 2013-04-04 09:18:09
是的,我做了,绑定中继器之前移动关系 – Anuya 2013-04-04 09:20:50