473,511 Members | 10,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WebControls.ListItem)': Value of type 'Admin.clsSites'
cannot be converted to 'System.Web.UI.WebControls.ListItem'

This is my code:
Public Sub LoadSites()
'Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
'cboSites.BeginUpdate()
Dim xDoc As New XmlDocument
xDoc.Load(Server.MapPath("\config.sites.xml"))
Dim xNodelist As XmlNodeList =
xDoc.SelectNodes("/sitedata/site")

For Each xNode As XmlNode In xNodelist
Dim Site As New clsSites
Site.Name = xNode.Attributes.GetNamedItem("name").Value
Site.Server = xNode.ChildNodes.Item(0).InnerText
Me.cboSites.Items.Add(Site) <---ERROR HERE

Next
cboSites.EndUpdate()
Cursor.Current = System.Windows.Forms.Cursors.Default
End Sub

Anyone know how to fix this?

Nov 23 '05 #1
6 3179
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

Nov 23 '05 #2
Yes - don't try to call methods that don't exist.

There is no method Add in ListItemCollection 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" <th**********@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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.WebControls.ListItem)': Value of type 'Admin.clsSites'
cannot be converted to 'System.Web.UI.WebControls.ListItem'

This is my code:
Public Sub LoadSites()
'Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
'cboSites.BeginUpdate()
Dim xDoc As New XmlDocument
xDoc.Load(Server.MapPath("\config.sites.xml"))
Dim xNodelist As XmlNodeList =
xDoc.SelectNodes("/sitedata/site")

For Each xNode As XmlNode In xNodelist
Dim Site As New clsSites
Site.Name = xNode.Attributes.GetNamedItem("name").Value
Site.Server = xNode.ChildNodes.Item(0).InnerText
Me.cboSites.Items.Add(Site) <---ERROR HERE

Next
cboSites.EndUpdate()
Cursor.Current = System.Windows.Forms.Cursors.Default
End Sub

Anyone know how to fix this?

Nov 23 '05 #3
multisync wrote:
For Each xNode As XmlNode In xNodelist
Dim Site As New clsSites
Site.Name = xNode.Attributes.GetNamedItem("name").Value
Site.Server = xNode.ChildNodes.Item(0).InnerText
Me.cboSites.Items.Add(Site) <---ERROR HERE
Next


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.Items.Add(New ListItem(Site.Name, 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.

Nov 23 '05 #4
Now i get an error at the cboSites.EndUpdate() line.

Nov 23 '05 #5
The original code was written in vb.net i'm trying to convert it to
asp.net

Nov 23 '05 #6
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
Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4320
by: Piotre Ugrumov | last post by:
I have tried to implement the overload of these 2 operators. ostream & operator<<(ostream &out, Person &p){ out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl; return out; }...
1
2041
by: Piotre Ugrumov | last post by:
I'm following your help. I have written the overload of the operator <<. This overload work! :-) But I have some problem with the overload of the operator >>. I have written the overload of this...
3
2222
by: Piotre Ugrumov | last post by:
I have done the overload on the operator >> and << in the class Attore. These 2 overload work correctly. I have done the overload of the same overload in the class Film. The class film ha inside...
6
1673
by: Hunter Hou | last post by:
Hi, I have this program, compiling is passed, but when i wanted to get the executable file(g++ -o output input.o), it fails. Who can lead me where the error is? Thanks, Hunter ===
7
4659
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++...
1
1055
by: Peteroid | last post by:
Ok, what am I do wrong here. I created a class with a public method, and when I try to create a new overload of it in a derived child class it won't let me: class Parent_Class { public: long ...
0
2577
by: Eph0nk | last post by:
Hi, I get an overload resolution failed error (Overload resolution failed because no accessible 'New' can be called without a narrowing conversion), and I can't seem to find a lot of relevant...
9
2367
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
5
2594
by: phiefer3 | last post by:
I'm currently a student, but this problem isn't directly related to what I have to do on an assignment. It's just a problem I've had with some supporting features. First of all, I'm using MSVS...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.