Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.aspnet.mobile
Problem with formatting date in dropdown list and list
aileen82
3/22/2005 1:27:00 PM
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..
-
aileen8
-----------------------------------------------------------------------
Posted via
http://www.codec...
-----------------------------------------------------------------------
1 Answer
Chance Hopkins
3/23/2005 7:23:00 AM
0
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
"aileen82" <aileen82.1mavtp@mail.codecomments.com> wrote in message
news:aileen82.1mavtp@mail.codecomments.com...
>
> hello,
>
> i am facing problem in formatting the date in dropdown list. below is
> 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.Net
> mobile, i got the error as "InvalidCastException: Specified cast is not
> 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) in
> 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 list
> control??
>
> Thanksss...
>
>
>
> --
> aileen82
> ------------------------------------------------------------------------
> Posted via
http://www.codeco...
> ------------------------------------------------------------------------
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Problem with formatting date in dropdown list and list
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password