Hi all,
Thanks for your help.
I used Steve Cheng's method and Steve Orr's comment is right. It is because
of unseen character problem. Also the Option Strict on does give me some
ideas why sometimes I have problem with my code. I willpost in another
message.
Dim plan As String
plan = CType(Session("Plan"), String)
When I moved mouse over the plan variable, if gives me the chance to find
out(you can not see in the watch window, or through reponse.write) that
plan="Plan I
". It seems not only it contains empty space, it also
contain a line feeder character. it came to my mind that I set up the
control:
<td><asp:dropdownlist id="PlanList1" runat="server">
<asp:ListItem>Choose</asp:ListItem>
<asp:ListItem>Plan I
</asp:ListItem>
<asp:ListItem>Plan II
</asp:ListItem>
</asp:dropdownlist></td>
Later on I changed without the newline in the control, it fixed the problem.
It didn't make me feel so crazy anymore. Look like as follow.
td><asp:dropdownlist id="PlanList1" runat="server">
<asp:ListItem>Choose</asp:ListItem>
<asp:ListItem>Plan I</asp:ListItem>
<asp:ListItem>Plan II</asp:ListItem>
</asp:dropdownlist></td>
I never know it will matter, what people usually do in this code without
change the .aspx page control set up?
--
Betty
"Karl Seguin [MVP]" wrote:
> Agree...this should be easy to figure out if you either debug the code or
> simply Response.Write or Trace.Warn out a couple values.
>
> Also, on top of CType() and ToString(), I'd personally use
> Cstr(Session("Plan"))...one isn't hands down better than the other 
>
> You should also make sure Option Strict is turned on in your project
> settings (it might already be, there's nothing in your code that indicates
> it isn't).
>
> Karl
>
> --
> http://www.openmymind.net/
>
>
>
> "Steve C. Orr" <> wrote in message
> news:86829AE8-AD7A-4660-90B8-...
> > That sounds pretty strange indeed. Sounds like some serious debugging is
> > needed. Perhaps the value has a hidden character in it such as Chr(0) or
> > something...
> >
> > --
> > I hope this helps,
> > Steve C. Orr
> > MCSD, MVP
> > http://Steve.Orr.net
> >
> >
> >
> > "c676228" wrote:
> >
> >> Steve,
> >> Thank you. I just tried.
> >> Session("Plan").ToString() give me value "Plan I" string,
> >> but when execute the following
> >> IF Session("Plan").ToString() = "Plan I" THEN
> >> Code 1
> >>
> >> ELSE
> >> Code 2
> >> END IF
> >> It doesn't go to code 1, it goes to code 2. I cannot believe my eyes.
> >> Am I daydreaming?
> >>
> >> --
> >> Betty
> >>
> >>
> >> "Steve C. Orr" wrote:
> >>
> >> > I think this syntax will work better for you:
> >> >
> >> > IF Session("Plan").ToString() = "Plan I" THEN...
> >> >
> >> > --
> >> > I hope this helps,
> >> > Steve C. Orr
> >> > MCSD, MVP
> >> > http://Steve.Orr.net
> >> >
> >> >
> >> >
> >> > "c676228" wrote:
> >> >
> >> > > Hi all,
> >> > > I have the code: If Session("Plan") = "Plan I" Then...
> >> > > I was just aware of that the Session("Plan") is an object, with
> >> > > String value
> >> > > "Plan I", but I don't know how to compare them and it never equals. I
> >> > > have
> >> > > tried to use
> >> > > Session("Plan").GetType.ToString.CompareTo("Plan I"), it always get 1
> >> > > even
> >> > > the value for Session("Plan") is "Plan I". Can you help?
> >> > > thank you.
> >> > >
> >> > > --
> >> > > Betty
>
>
>