0

我正在尝试用里面的复选框做一个嵌套的中继器控件。基本上,我想要的是对复选框进行分类,例如,

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

我错过了什么?

4

2 回答 2

3

您应该检查事件中触发了哪个 itemtype ItemDataBound,这可能是问题,也可能不是问题,因为您没有页眉和页脚模板,但这仍然是一个好习惯。

Protected Sub rp_Groups_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rp_Groups.ItemDataBound
  If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
    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 If
End Sub

编辑

我刚刚注意到您在绑定中继器的数据源之后添加了关系。.databind添加关系后尝试移动。

编辑 2

好的,你可以试试这个。添加datatablesdataset并将转发器数据源设置为:ds.Tables(0)

Public Sub Fill() 
    Dim ds As New DataSet() 
    Dim dtServiceCategory As DataTable = ServiceTypeModel.GetService_Categories()
    Dim dtServiceType As DataTable = ServiceTypeModel.Search("", True)
    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)
    relation.Nested = True
    ds.Relations.Add(relation)

    rp_Groups.DataSource = ds.Tables(0)
    rp_Groups.DataBind()
End Sub
于 2013-04-04T08:57:57.887 回答
0

确保您已导入命名空间 System.Data

尝试添加

<%@ Import Namespace="System.Data" %>

到您的 ASPX 文件。

作为另一种选择,您可以全局导入命名空间,而不仅仅是在一个页面中:

http://msmvps.com/blogs/simpleman/archive/2006/01/11/80804.aspx

于 2013-04-04T08:45:57.117 回答