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

ヘッダーとフッターのテンプレートがないため、イベントでどのアイテムタイプが発生しているかを確認する必要があり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

OK、これを試してみませんか。を に追加し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ファイルに。

別のオプションとして、1 つのページだけでなく、グローバルに名前空間をインポートできます。

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

于 2013-04-04T08:45:57.117 に答える