Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 13th, 2008, 08:46 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Typecasting for arrayList

Hi
I am trying to retrieve the value at index 0 of an arraylist as string But keep getting the error message "Conversion from type 'BlogInfo' to type 'String' is not valid." . Please help me out...



dim list as new Arraylist
dim Tempstr as string

Dim m_oBlog As New BlogInfo ---> Dotnetnuke.modules.blog.business.BlogInfo
.......
.......
.......
.......

list.Add(m_oBlog)
TempStr = Convert.ToString(list.Item(0))


There are items in the list, so the list is defenitely not empty....


Many Thanks

Sheraz
Reply With Quote
  #2 (permalink)  
Old February 13th, 2008, 09:29 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Isn't this error somewhat obvious? Position 0 in your array is not of Type string, it is of type BlogInfo which is why your conversion fails.

I am not that familiar with DNN but you should be able to do this:
Dim TempStr as BlogInfo = CType(list.Item(0), BlogInfo)

You can then access the BlogInfo object from the array in this manner:
TempStr.SomeMethod()

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old February 13th, 2008, 10:48 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks buddy its working now..

Reply With Quote
  #4 (permalink)  
Old February 13th, 2008, 11:45 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad it worked out for you. =]

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #5 (permalink)  
Old February 13th, 2008, 01:13 PM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you like you create your own strongly typed list class by deriving CollectionBase class and implementing your own Add/Remove/Insert/WhatEver methods. See example here: http://msdn2.microsoft.com/en-us/lib...ctionbase.aspx

Reply With Quote
  #6 (permalink)  
Old February 13th, 2008, 03:16 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Or even easier, just use a generic list for your desired type.

-Peter
Reply With Quote
  #7 (permalink)  
Old February 13th, 2008, 03:48 PM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah. Stupid me. This was ASP.NET 2 discussion :)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList Mogg-Way C# 2005 5 February 12th, 2008 04:05 PM
SiteIdentity TypeCasting Problem RM82 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 17th, 2005 10:38 AM
Help with an arraylist crazy-nun General .NET 4 July 14th, 2005 03:32 AM
typecasting int to java.lang.Integer ruchilalla J2EE 1 May 23rd, 2005 06:11 AM
ArrayList kobystud C# 4 May 25th, 2004 02:05 PM



All times are GMT -4. The time now is 10:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.