Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Mobile / March 2005

Tip: Looking for answers? Try searching our database.

Problem with formatting date in dropdown list and list

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aileen82 - 22 Mar 2005 13:30 GMT
hello,

i am facing problem in formatting the date in dropdown list. below i
my source code:

myConn.Open()
drCin = cmdCin.ExecuteReader
radSelectCinema.DataSource = drCin
radSelectCinema.DataTextField = "Cin_Name"
radSelectCinema.DataValueField = "Cin_ID"
radSelectCinema.DataBind()
drCin.Close()

drDate = cmdDate.ExecuteReader
drplstDate.DataSource = drDate
drplstDate.DataTextField = "Show_Date"
drplstDate.DataBind()
drDate.Close()
myConn.Close()

For Each itm As ListItem In drplstDate.Items
Dim tempdate As Date

tempdate = itm.Text
itm.Text = tempdate.ToShortDateString()
Next

The code works fine in ASP.net but when i copy and run it in ASP.Ne
mobile, i got the error as "InvalidCastException: Specified cast is no
valid."

Here is the source error:
Line 68:             myConn.Close()
Line 69:
Line 70:             For Each itm As ListItem In drplstDate.Items
Line 71:                 Dim tempdate As Date
Line 72:

Stack Trace:
[InvalidCastException: Specified cast is not valid.]
MobileWebApplication1.ShowtimesMenu.Page_Load(Object sender
EventArgs e) i
C:\Inetpub\wwwroot\MobileWebApplication1\ShowtimesMenu.aspx.vb:70
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.MobileControls.MobilePage.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

i also facing problem wif formatting the date in mobile list control
Do anyone know how to format the date to shortdatestring in mobile lis
control??

Thanksss..


Chance Hopkins - 23 Mar 2005 08:20 GMT
It's this line:
tempdate = itm.Text

you are casting a string to a datetime object

You need something like this:

'Put this outside the for each loop
'no point in defining it againa and again.
Dim tempdate As Date

For Each itm As ListItem In drplstDate.Items
tempdate = System.DateTime.Parse(itm.Text)
itm.Text = tempdate.ToShortDateString()
Next

or one line

For Each itm As ListItem In drplstDate.Items
itm.Text = System.DateTime.Parse(itm.Text).ToShortDateString()
Next

> hello,
>
[quoted text clipped - 55 lines]
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.