Error: No default member found for type MyClass

Discussion in 'ASP .Net' started by Andy Eshtry, Feb 13, 2004.

  1. Andy Eshtry

    Andy Eshtry Guest

    Dear Friends
    I have a urgent problem to solve. I have created a class and its
    collection and then bind it to a datagrid but got the following error.
    Please help. Thanks in advance. Andy Eshtry

    No default member found for type 'clsAgentPostalCode'

    Line 44: Dim oAgentPostalCodeCollection As New

    clsAgentPostalCodeCollection(lAgentID)
    Line 45: dgPostalCode.DataSource = oAgentPostalCodeCollection
    Line 46: dgPostalCode.DataBind()

    ----------------------------code in aspx
    file ---------------------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If Not Page.IsPostBack Then

    dgPostalCode.DataKeyField = "AssignedPostalCodeID"
    'dgPostalCode.DataSource = GetPostalCodeList()
    Dim oAgentPostalCodeCollection As New
    clsAgentPostalCodeCollection(lAgentID)
    dgPostalCode.DataSource = oAgentPostalCodeCollection
    dgPostalCode.DataBind()

    End If
    End Sub
    --------------------clsAgentPostalCode -------------------------------------
    ------

    Public Class clsAgentPostalCode
    Public mAgentPostalCodeID As Long
    Public mAssignedPostalCodeID As Long
    Public mAgentID As Long
    Public mAssignedPostalCode As String
    Private mSelected As Boolean
    Private mPrevSelected As Boolean

    Public ReadOnly Property AgentPostalCodeID() As Long
    Get
    Return mAgentPostalCodeID
    End Get
    End Property

    Public ReadOnly Property AgentID() As Long
    Get
    Return mAgentID
    End Get
    End Property

    Public ReadOnly Property AssignedPostalCode() As String
    Get
    Return mAssignedPostalCode
    End Get
    End Property


    Public ReadOnly Property AssignedPostalCodeID() As Long
    Get
    Return mAssignedPostalCodeID
    End Get
    End Property

    Public Sub New(ByVal parAssignedPostalCodeID As Long, ByVal parSelected
    As Boolean, _
    ByVal parAssignedPostalCode As String, ByVal parAgentPostalCodeID As
    Long, ByVal parAgentID

    As Long)


    mAgentPostalCodeID = parAgentPostalCodeID
    mAssignedPostalCodeID = parAssignedPostalCodeID

    mAgentID = parAgentID
    mSelected = parSelected
    mPrevSelected = parSelected
    mAssignedPostalCode = parAssignedPostalCode
    End Sub

    Public Property Selected() As Boolean
    Get
    Return Selected
    End Get
    Set(ByVal Value As Boolean)
    Selected = Value
    End Set
    End Property


    End Sub
    End Class

    ---------------------clsAgentPostalCodeCollection-----------------------

    Imports System.Collections
    Public Class clsAgentPostalCodeCollection
    Inherits CollectionBase

    Public Sub New(ByVal parAgentID As Long)
    Dim sConStr As String
    Dim oConfSetting As ConfigurationSettings
    sConStr = oConfSetting.AppSettings("ConStr").ToString()
    Dim Cn As SqlConnection
    Dim daPostalCode As SqlDataAdapter
    Dim dsPostalCode As New DataSet()
    Try
    Cn = New SqlConnection(sConStr)

    Dim cmdSel As SqlCommand = New
    SqlCommand("spAgentAssignedPostalCode", Cn)
    cmdSel.CommandType = CommandType.StoredProcedure
    cmdSel.Parameters.Add(New SqlParameter("@AgentID", parAgentID))
    Cn.Open()
    daPostalCode = New SqlDataAdapter(cmdSel)
    daPostalCode.Fill(dsPostalCode, "tblPostalCode")
    Cn.Close()

    Dim AgentPostalCodeRow As DataRow
    For Each AgentPostalCodeRow In
    dsPostalCode.Tables("tblPostalCode").Rows
    Dim par1 As Long =
    AgentPostalCodeRow.Item("AssignedPostalCodeID")
    Dim par2 As Boolean = AgentPostalCodeRow.Item("Selected")
    Dim par3 As String =
    AgentPostalCodeRow.Item("AssignedPostalCode")
    Dim par4 As Long
    If Not
    IsDBNull(AgentPostalCodeRow.Item("AgentPostalCodeID")) Then
    par4 = AgentPostalCodeRow.Item("AgentPostalCodeID")
    Else
    par4 = 0
    End If
    Dim par5 As Long

    If Not IsDBNull(AgentPostalCodeRow.Item("ID_Agent")) Then
    par5 = AgentPostalCodeRow.Item("ID_Agent")
    Else
    par5 = 0
    End If

    Dim AgentPostalCodeItem As New clsAgentPostalCode(par1,
    par2, par3, par4, par5)
    Add(AgentPostalCodeItem)
    Next
    Catch ex As Exception
    Throw ex
    End Try

    End Sub

    Public Sub Add(ByVal AgentPostalCodeItem As clsAgentPostalCode)

    List.Add(AgentPostalCodeItem)
    End Sub

    Public Sub Remove(ByVal index As Integer)

    If (index > Count - 1 Or index < 0) Then

    Else
    List.RemoveAt(index)

    End If
    End Sub

    Public Function Item(ByVal Index As Integer) As clsAgentPostalCode

    Return CType(List(Index), clsAgentPostalCode)
    End Function

    Public ReadOnly Property Length() As Long
    Get
    Return List.Count
    End Get
    End Property

    Public Function Find(ByVal id As Long) As clsAgentPostalCode
    Dim AgentPostalCodeItem As clsAgentPostalCode

    For Each AgentPostalCodeItem In InnerList
    If AgentPostalCodeItem.AgentPostalCodeID = id Then
    Return AgentPostalCodeItem
    End If
    Next
    Return Nothing
    End Function

    End Class
    Andy Eshtry, Feb 13, 2004
    #1
    1. Advertising

  2. Andy Eshtry

    Teemu Keiski Guest

    With quick look you have Item as function in clsAgentPostalCodeCollection
    and it should be a property (default property)

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "Andy Eshtry" <> wrote in message
    news:...
    Dear Friends
    I have a urgent problem to solve. I have created a class and its
    collection and then bind it to a datagrid but got the following error.
    Please help. Thanks in advance. Andy Eshtry

    No default member found for type 'clsAgentPostalCode'

    Line 44: Dim oAgentPostalCodeCollection As New

    clsAgentPostalCodeCollection(lAgentID)
    Line 45: dgPostalCode.DataSource = oAgentPostalCodeCollection
    Line 46: dgPostalCode.DataBind()

    ----------------------------code in aspx
    file ---------------------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If Not Page.IsPostBack Then

    dgPostalCode.DataKeyField = "AssignedPostalCodeID"
    'dgPostalCode.DataSource = GetPostalCodeList()
    Dim oAgentPostalCodeCollection As New
    clsAgentPostalCodeCollection(lAgentID)
    dgPostalCode.DataSource = oAgentPostalCodeCollection
    dgPostalCode.DataBind()

    End If
    End Sub
    --------------------clsAgentPostalCode -------------------------------------
    ------

    Public Class clsAgentPostalCode
    Public mAgentPostalCodeID As Long
    Public mAssignedPostalCodeID As Long
    Public mAgentID As Long
    Public mAssignedPostalCode As String
    Private mSelected As Boolean
    Private mPrevSelected As Boolean

    Public ReadOnly Property AgentPostalCodeID() As Long
    Get
    Return mAgentPostalCodeID
    End Get
    End Property

    Public ReadOnly Property AgentID() As Long
    Get
    Return mAgentID
    End Get
    End Property

    Public ReadOnly Property AssignedPostalCode() As String
    Get
    Return mAssignedPostalCode
    End Get
    End Property


    Public ReadOnly Property AssignedPostalCodeID() As Long
    Get
    Return mAssignedPostalCodeID
    End Get
    End Property

    Public Sub New(ByVal parAssignedPostalCodeID As Long, ByVal parSelected
    As Boolean, _
    ByVal parAssignedPostalCode As String, ByVal parAgentPostalCodeID As
    Long, ByVal parAgentID

    As Long)


    mAgentPostalCodeID = parAgentPostalCodeID
    mAssignedPostalCodeID = parAssignedPostalCodeID

    mAgentID = parAgentID
    mSelected = parSelected
    mPrevSelected = parSelected
    mAssignedPostalCode = parAssignedPostalCode
    End Sub

    Public Property Selected() As Boolean
    Get
    Return Selected
    End Get
    Set(ByVal Value As Boolean)
    Selected = Value
    End Set
    End Property


    End Sub
    End Class

    ---------------------clsAgentPostalCodeCollection-----------------------

    Imports System.Collections
    Public Class clsAgentPostalCodeCollection
    Inherits CollectionBase

    Public Sub New(ByVal parAgentID As Long)
    Dim sConStr As String
    Dim oConfSetting As ConfigurationSettings
    sConStr = oConfSetting.AppSettings("ConStr").ToString()
    Dim Cn As SqlConnection
    Dim daPostalCode As SqlDataAdapter
    Dim dsPostalCode As New DataSet()
    Try
    Cn = New SqlConnection(sConStr)

    Dim cmdSel As SqlCommand = New
    SqlCommand("spAgentAssignedPostalCode", Cn)
    cmdSel.CommandType = CommandType.StoredProcedure
    cmdSel.Parameters.Add(New SqlParameter("@AgentID", parAgentID))
    Cn.Open()
    daPostalCode = New SqlDataAdapter(cmdSel)
    daPostalCode.Fill(dsPostalCode, "tblPostalCode")
    Cn.Close()

    Dim AgentPostalCodeRow As DataRow
    For Each AgentPostalCodeRow In
    dsPostalCode.Tables("tblPostalCode").Rows
    Dim par1 As Long =
    AgentPostalCodeRow.Item("AssignedPostalCodeID")
    Dim par2 As Boolean = AgentPostalCodeRow.Item("Selected")
    Dim par3 As String =
    AgentPostalCodeRow.Item("AssignedPostalCode")
    Dim par4 As Long
    If Not
    IsDBNull(AgentPostalCodeRow.Item("AgentPostalCodeID")) Then
    par4 = AgentPostalCodeRow.Item("AgentPostalCodeID")
    Else
    par4 = 0
    End If
    Dim par5 As Long

    If Not IsDBNull(AgentPostalCodeRow.Item("ID_Agent")) Then
    par5 = AgentPostalCodeRow.Item("ID_Agent")
    Else
    par5 = 0
    End If

    Dim AgentPostalCodeItem As New clsAgentPostalCode(par1,
    par2, par3, par4, par5)
    Add(AgentPostalCodeItem)
    Next
    Catch ex As Exception
    Throw ex
    End Try

    End Sub

    Public Sub Add(ByVal AgentPostalCodeItem As clsAgentPostalCode)

    List.Add(AgentPostalCodeItem)
    End Sub

    Public Sub Remove(ByVal index As Integer)

    If (index > Count - 1 Or index < 0) Then

    Else
    List.RemoveAt(index)

    End If
    End Sub

    Public Function Item(ByVal Index As Integer) As clsAgentPostalCode

    Return CType(List(Index), clsAgentPostalCode)
    End Function

    Public ReadOnly Property Length() As Long
    Get
    Return List.Count
    End Get
    End Property

    Public Function Find(ByVal id As Long) As clsAgentPostalCode
    Dim AgentPostalCodeItem As clsAgentPostalCode

    For Each AgentPostalCodeItem In InnerList
    If AgentPostalCodeItem.AgentPostalCodeID = id Then
    Return AgentPostalCodeItem
    End If
    Next
    Return Nothing
    End Function

    End Class
    Teemu Keiski, Feb 14, 2004
    #2
    1. Advertising

  3. Andy Eshtry

    Teemu Keiski Guest

    And of course it's not the reason...as the error states it is trying to bind
    to 'clsAgentPostalCode' and you probably haven't provided the property (in
    databinding syntax) which the binding should occur to. Therefore it asks for
    the default property for 'clsAgentPostalCode '

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist



    "Teemu Keiski" <> wrote in message
    news:...
    With quick look you have Item as function in clsAgentPostalCodeCollection
    and it should be a property (default property)

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "Andy Eshtry" <> wrote in message
    news:...
    Dear Friends
    I have a urgent problem to solve. I have created a class and its
    collection and then bind it to a datagrid but got the following error.
    Please help. Thanks in advance. Andy Eshtry

    No default member found for type 'clsAgentPostalCode'

    Line 44: Dim oAgentPostalCodeCollection As New

    clsAgentPostalCodeCollection(lAgentID)
    Line 45: dgPostalCode.DataSource = oAgentPostalCodeCollection
    Line 46: dgPostalCode.DataBind()

    ----------------------------code in aspx
    file ---------------------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If Not Page.IsPostBack Then

    dgPostalCode.DataKeyField = "AssignedPostalCodeID"
    'dgPostalCode.DataSource = GetPostalCodeList()
    Dim oAgentPostalCodeCollection As New
    clsAgentPostalCodeCollection(lAgentID)
    dgPostalCode.DataSource = oAgentPostalCodeCollection
    dgPostalCode.DataBind()

    End If
    End Sub
    --------------------clsAgentPostalCode -------------------------------------
    ------

    Public Class clsAgentPostalCode
    Public mAgentPostalCodeID As Long
    Public mAssignedPostalCodeID As Long
    Public mAgentID As Long
    Public mAssignedPostalCode As String
    Private mSelected As Boolean
    Private mPrevSelected As Boolean

    Public ReadOnly Property AgentPostalCodeID() As Long
    Get
    Return mAgentPostalCodeID
    End Get
    End Property

    Public ReadOnly Property AgentID() As Long
    Get
    Return mAgentID
    End Get
    End Property

    Public ReadOnly Property AssignedPostalCode() As String
    Get
    Return mAssignedPostalCode
    End Get
    End Property


    Public ReadOnly Property AssignedPostalCodeID() As Long
    Get
    Return mAssignedPostalCodeID
    End Get
    End Property

    Public Sub New(ByVal parAssignedPostalCodeID As Long, ByVal parSelected
    As Boolean, _
    ByVal parAssignedPostalCode As String, ByVal parAgentPostalCodeID As
    Long, ByVal parAgentID

    As Long)


    mAgentPostalCodeID = parAgentPostalCodeID
    mAssignedPostalCodeID = parAssignedPostalCodeID

    mAgentID = parAgentID
    mSelected = parSelected
    mPrevSelected = parSelected
    mAssignedPostalCode = parAssignedPostalCode
    End Sub

    Public Property Selected() As Boolean
    Get
    Return Selected
    End Get
    Set(ByVal Value As Boolean)
    Selected = Value
    End Set
    End Property


    End Sub
    End Class

    ---------------------clsAgentPostalCodeCollection-----------------------

    Imports System.Collections
    Public Class clsAgentPostalCodeCollection
    Inherits CollectionBase

    Public Sub New(ByVal parAgentID As Long)
    Dim sConStr As String
    Dim oConfSetting As ConfigurationSettings
    sConStr = oConfSetting.AppSettings("ConStr").ToString()
    Dim Cn As SqlConnection
    Dim daPostalCode As SqlDataAdapter
    Dim dsPostalCode As New DataSet()
    Try
    Cn = New SqlConnection(sConStr)

    Dim cmdSel As SqlCommand = New
    SqlCommand("spAgentAssignedPostalCode", Cn)
    cmdSel.CommandType = CommandType.StoredProcedure
    cmdSel.Parameters.Add(New SqlParameter("@AgentID", parAgentID))
    Cn.Open()
    daPostalCode = New SqlDataAdapter(cmdSel)
    daPostalCode.Fill(dsPostalCode, "tblPostalCode")
    Cn.Close()

    Dim AgentPostalCodeRow As DataRow
    For Each AgentPostalCodeRow In
    dsPostalCode.Tables("tblPostalCode").Rows
    Dim par1 As Long =
    AgentPostalCodeRow.Item("AssignedPostalCodeID")
    Dim par2 As Boolean = AgentPostalCodeRow.Item("Selected")
    Dim par3 As String =
    AgentPostalCodeRow.Item("AssignedPostalCode")
    Dim par4 As Long
    If Not
    IsDBNull(AgentPostalCodeRow.Item("AgentPostalCodeID")) Then
    par4 = AgentPostalCodeRow.Item("AgentPostalCodeID")
    Else
    par4 = 0
    End If
    Dim par5 As Long

    If Not IsDBNull(AgentPostalCodeRow.Item("ID_Agent")) Then
    par5 = AgentPostalCodeRow.Item("ID_Agent")
    Else
    par5 = 0
    End If

    Dim AgentPostalCodeItem As New clsAgentPostalCode(par1,
    par2, par3, par4, par5)
    Add(AgentPostalCodeItem)
    Next
    Catch ex As Exception
    Throw ex
    End Try

    End Sub

    Public Sub Add(ByVal AgentPostalCodeItem As clsAgentPostalCode)

    List.Add(AgentPostalCodeItem)
    End Sub

    Public Sub Remove(ByVal index As Integer)

    If (index > Count - 1 Or index < 0) Then

    Else
    List.RemoveAt(index)

    End If
    End Sub

    Public Function Item(ByVal Index As Integer) As clsAgentPostalCode

    Return CType(List(Index), clsAgentPostalCode)
    End Function

    Public ReadOnly Property Length() As Long
    Get
    Return List.Count
    End Get
    End Property

    Public Function Find(ByVal id As Long) As clsAgentPostalCode
    Dim AgentPostalCodeItem As clsAgentPostalCode

    For Each AgentPostalCodeItem In InnerList
    If AgentPostalCodeItem.AgentPostalCodeID = id Then
    Return AgentPostalCodeItem
    End If
    Next
    Return Nothing
    End Function

    End Class
    Teemu Keiski, Feb 14, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mario Fratelli
    Replies:
    32
    Views:
    1,353
    Phlip
    Dec 9, 2003
  2. Dave
    Replies:
    1
    Views:
    341
    Ron Natalie
    Dec 8, 2003
  3. modemer
    Replies:
    11
    Views:
    624
    modemer
    Mar 21, 2005
  4. Andy Eshtry

    Error: No default member found for type MyClass

    Andy Eshtry, Feb 13, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    185
    Andy Eshtry
    Feb 13, 2004
  5. Rob
    Replies:
    1
    Views:
    203
Loading...

Share This Page