Getting Overload error with ASP.NET using VB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • multisync

    Getting Overload error with ASP.NET using VB

    I'm getting the following error:

    Overload resolution failed because no accessible 'Add' can be called
    with these arguments: 'Public Sub Add(item As
    System.Web.UI.W ebControls.List Item)': Value of type 'Admin.clsSites '
    cannot be converted to 'System.Web.UI. WebControls.Lis tItem'

    This is my code:
    Public Sub LoadSites()
    'Cursor.Current = System.Windows. Forms.Cursors.W aitCursor
    'cboSites.Begin Update()
    Dim xDoc As New XmlDocument
    xDoc.Load(Serve r.MapPath("\con fig.sites.xml") )
    Dim xNodelist As XmlNodeList =
    xDoc.SelectNode s("/sitedata/site")

    For Each xNode As XmlNode In xNodelist
    Dim Site As New clsSites
    Site.Name = xNode.Attribute s.GetNamedItem( "name").Val ue
    Site.Server = xNode.ChildNode s.Item(0).Inner Text
    Me.cboSites.Ite ms.Add(Site) <---ERROR HERE

    Next
    cboSites.EndUpd ate()
    Cursor.Current = System.Windows. Forms.Cursors.D efault
    End Sub

    Anyone know how to fix this?

  • multisync

    #2
    Re: Getting Overload error with ASP.NET using VB

    Public Class clsSites
    Public Name As String
    Public Server As String
    Sub New()
    MyBase.New()
    End Sub
    Public Overrides Function ToString() As String
    Return Me.Name
    End Function

    End Class

    Comment

    • Marina

      #3
      Re: Getting Overload error with ASP.NET using VB

      Yes - don't try to call methods that don't exist.

      There is no method Add in ListItemCollect ion that takes an instance of
      clsSite. And how could there possibly be? That is a class you wrote! It's
      not like Microsoft could possibly know about it and define an overload just
      for you.

      "multisync" <thenextrocky@h otmail.com> wrote in message
      news:1132343696 .008107.120070@ g43g2000cwa.goo glegroups.com.. .[color=blue]
      > I'm getting the following error:
      >
      > Overload resolution failed because no accessible 'Add' can be called
      > with these arguments: 'Public Sub Add(item As
      > System.Web.UI.W ebControls.List Item)': Value of type 'Admin.clsSites '
      > cannot be converted to 'System.Web.UI. WebControls.Lis tItem'
      >
      > This is my code:
      > Public Sub LoadSites()
      > 'Cursor.Current = System.Windows. Forms.Cursors.W aitCursor
      > 'cboSites.Begin Update()
      > Dim xDoc As New XmlDocument
      > xDoc.Load(Serve r.MapPath("\con fig.sites.xml") )
      > Dim xNodelist As XmlNodeList =
      > xDoc.SelectNode s("/sitedata/site")
      >
      > For Each xNode As XmlNode In xNodelist
      > Dim Site As New clsSites
      > Site.Name = xNode.Attribute s.GetNamedItem( "name").Val ue
      > Site.Server = xNode.ChildNode s.Item(0).Inner Text
      > Me.cboSites.Ite ms.Add(Site) <---ERROR HERE
      >
      > Next
      > cboSites.EndUpd ate()
      > Cursor.Current = System.Windows. Forms.Cursors.D efault
      > End Sub
      >
      > Anyone know how to fix this?
      >[/color]


      Comment

      • Chris Dunaway

        #4
        Re: Getting Overload error with ASP.NET using VB

        multisync wrote:[color=blue]
        > For Each xNode As XmlNode In xNodelist
        > Dim Site As New clsSites
        > Site.Name = xNode.Attribute s.GetNamedItem( "name").Val ue
        > Site.Server = xNode.ChildNode s.Item(0).Inner Text
        > Me.cboSites.Ite ms.Add(Site) <---ERROR HERE
        > Next[/color]

        The problem is that 'Site' is not an object of type 'ListItem' which is
        what the cboSites.Items. Add method is expecting.

        Try this (untested):

        Me.cboSites.Ite ms.Add(New ListItem(Site.N ame, Site.Server))

        What this does is create a new ListItem object, assign the properties
        of your Site object to the text and value properties of the ListItem
        and then finally adds the ListItem to the combo.

        Comment

        • multisync

          #5
          Re: Getting Overload error with ASP.NET using VB

          Now i get an error at the cboSites.EndUpd ate() line.

          Comment

          • multisync

            #6
            Re: Getting Overload error with ASP.NET using VB

            The original code was written in vb.net i'm trying to convert it to
            asp.net

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Getting Overload error with ASP.NET using VB

              multisync,

              I assume that the cbo is a dropdownlist.

              As Marina wrote already can you not add an object to it, in a not databound
              situation is it subpossed to get a string.

              You can however use the datasource, the datatextfield and the
              datavaluefield, however that is a complete other way of doing this.

              I hope this helps,

              Cor


              Comment

              Working...