0

I am trying to do a nested repeater control with check box inside. Basically, what i want is categorize the checkboxes like,

Group 1
   Item 1
   Item 2

Group 2
   Item 3
   Item 4

Group 3
   Item 5
   Item 6

The problem I am facing is, I getting the error :

Error 1 : 'DataRowView' is not declared. It may be inaccessible due to its protection level.
Error 2 : Name 'DataRowView' is not declared.

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>

Codebehind:

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

What am i missing ?

2 Answers 2

3

You should check which itemtype is being fired on the ItemDataBound event, this may or may not be the problem, as you don't have a header and footer template, however it is still good practice.

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

EDIT

I've just noticed that you are adding the relation after you have already binded the repeater's datasource. Try moving the .databind after the relation has been added.

EDIT 2

OK can you try this. Add the datatables to the dataset and set the repeaters datasource to: 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
Sign up to request clarification or add additional context in comments.

2 Comments

I tried both your ideas, and getting error : 'DataRowView' is a type in 'Data' and cannot be used as an expression. And when I remove datasource of checkboxlist, I am not getting any error !!!
Yes I did, moved the relation before binding the repeater
0

Ensure that you have imported namespace System.Data

Try to add

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

to your ASPX file.

As another option you can import namespaces globally, not only in one page:

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

1 Comment

Now i am getting error : 'DataRowView' is a type and cannot be used as an expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.