locked
How to Define class structure of type IList(Of eMallEntity.ItemCatagory) RRS feed

  • Question

  • User1909155429 posted

    I came across a script example minus the class structure for binding data to a listview control does anybody know how the classes are defined?

    i get error message: ILIST has no type parameters and so can not have type arguments

      Dim dtTblSubCategory As New DataTable()
            dtTblSubCategory = (New eMallBL()).getSubCategories(0, 0)
    
            Dim categories As IList(Of eMallEntity.ItemCatagory) = New List(Of eMallEntity.ItemCatagory)()
            For i As Integer = 0 To dtTblCategory.Rows.Count - 1
                Dim category As New eMallEntity.ItemCatagory()
                category.Name = dtTblCategory.Rows(i)("Name").ToString()
                category.ID = Convert.ToInt32(dtTblCategory.Rows(i)("ID").ToString())
                Dim subCategories As IList(Of eMallEntity.ItemSubCatagory) = New List(Of eMallEntity.ItemSubCatagory)()
                For j As Integer = 0 To dtTblSubCategory.Rows.Count - 1
                    If dtTblSubCategory.Rows(j)("CategoryID").ToString() = dtTblCategory.Rows(i)("ID").ToString() Then
                        Dim subCategory As New eMallEntity.ItemSubCatagory()
                        subCategory.Name = dtTblSubCategory.Rows(j)("Name").ToString()
                        subCategory.ID = Convert.ToInt32(dtTblSubCategory.Rows(j)("ID").ToString())
                        subCategories.Add(subCategory)
                    End If
                Next

    Tuesday, April 22, 2014 4:24 PM

Answers

  • User281315223 posted

    i dont have the classes !

    Try right-clicking on the actual classes themselves (ItemCatagory or ItemSubCategory) and choosing the "Go to Definition" option that appears within the context menu in Visual Studio.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 26, 2014 11:42 AM

All replies

  • User281315223 posted

    You should be fine without explicitly typing your variables.

    Try using :

    Dim categories = New List(Of eMallEntity.ItemCatagory)()

    instead of :

    Dim categories As IList(Of eMallEntity.ItemCatagory) = New List(Of eMallEntity.ItemCatagory)()

    Full example below :

    Dim dtTblSubCategory As New DataTable()
    dtTblSubCategory = (New eMallBL()).getSubCategories(0, 0)
    
    Dim categories = New List(Of eMallEntity.ItemCatagory)()
    For i As Integer = 0 To dtTblCategory.Rows.Count - 1
                Dim category As New eMallEntity.ItemCatagory()
                category.Name = dtTblCategory.Rows(i)("Name").ToString()
                category.ID = Convert.ToInt32(dtTblCategory.Rows(i)("ID").ToString())
                Dim subCategories = New List(Of eMallEntity.ItemSubCatagory)()
                For j As Integer = 0 To dtTblSubCategory.Rows.Count - 1
                    If dtTblSubCategory.Rows(j)("CategoryID").ToString() = dtTblCategory.Rows(i)("ID").ToString() Then
                        Dim subCategory As New eMallEntity.ItemSubCatagory()
                        subCategory.Name = dtTblSubCategory.Rows(j)("Name").ToString()
                        subCategory.ID = Convert.ToInt32(dtTblSubCategory.Rows(j)("ID").ToString())
                        subCategories.Add(subCategory)
                    End If
                Next
    Next

    Tuesday, April 22, 2014 4:28 PM
  • User1909155429 posted

    i think i have omitted some important code.

    it does not like the highlighted code ?

      

       Next
                category.subCategories = subCategories
                categories.Add(category)
            Next
            RightMenuItems.DataSource = categories
            RightMenuItems.DataBind()


    Thanks


     

    Thursday, April 24, 2014 6:47 PM
  • User281315223 posted

    Are you sure that your subCategories property on your category object is the same type as your subCategories variable (A List of ItemSubCategory objects)?

    Without seeing the actual classes themselves, it would be hard to determine exactly what the issue is. Do you have a particular error message with this?

    Friday, April 25, 2014 7:51 AM
  • User1909155429 posted

    it is correct syntax.

    you will get the same error message as mine when you place on page.

    i dont have the classes !

     

    Thanks

    Saturday, April 26, 2014 8:08 AM
  • User397347636 posted

    Are you sure that you have "Imports System.Collections.Generic" at the top of the page?

    It sounds like you are actually using System.Collections.IList, not System.Collections.Generic.IList - this would explain the error you are getting.

    Try explicitly declaring as System.Collections.Generic.IList and see what happens.

    Saturday, April 26, 2014 10:35 AM
  • User281315223 posted

    i dont have the classes !

    Try right-clicking on the actual classes themselves (ItemCatagory or ItemSubCategory) and choosing the "Go to Definition" option that appears within the context menu in Visual Studio.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 26, 2014 11:42 AM