DropDownList.SelectedValue

Discussion in 'ASP .Net' started by CK, May 17, 2006.

  1. CK

    CK Guest

    Hi All,
    I have a class and one property is an Enum. I am trying to persist the
    DropDownList.SelectedValue to the class property.
    I am using
    job.ExpRelated =
    Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);

    but it doesn't build. Any ideas anyone?

    Thanks All,

    ~CK
    CK, May 17, 2006
    #1
    1. Advertising

  2. CK

    Jeff Dillon Guest

    Do you get an error?

    Break it into pieces...hard-code SelectedValue etc until you find why it
    isn't working

    "CK" <> wrote in message
    news:qxNag.28618$...
    > Hi All,
    > I have a class and one property is an Enum. I am trying to persist the
    > DropDownList.SelectedValue to the class property.
    > I am using
    > job.ExpRelated =
    > Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >
    > but it doesn't build. Any ideas anyone?
    >
    > Thanks All,
    >
    > ~CK
    >
    >
    Jeff Dillon, May 17, 2006
    #2
    1. Advertising

  3. CK

    CK Guest

    I am sorry. I am a beginner. I am not quite sure what you mean.
    How do I do that?

    "Jeff Dillon" <> wrote in message
    news:...
    > Do you get an error?
    >
    > Break it into pieces...hard-code SelectedValue etc until you find why it
    > isn't working
    >
    > "CK" <> wrote in message
    > news:qxNag.28618$...
    >> Hi All,
    >> I have a class and one property is an Enum. I am trying to persist the
    >> DropDownList.SelectedValue to the class property.
    >> I am using
    >> job.ExpRelated =
    >> Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >>
    >> but it doesn't build. Any ideas anyone?
    >>
    >> Thanks All,
    >>
    >> ~CK
    >>
    >>

    >
    >
    CK, May 17, 2006
    #3
  4. CK

    Jeff Dillon Guest

    Instead of ddlExpRelated.SelectedValue, hard-code a specific value.

    Did you copy this code? Beginners generally don't know about Enum's and
    typeof...

    start with Job.ExpRelated = value

    then add pieces in one at a time to see where it's failing

    And post your error message

    Jeff

    "CK" <> wrote in message
    news:1TNag.28622$...
    >I am sorry. I am a beginner. I am not quite sure what you mean.
    > How do I do that?
    >
    > "Jeff Dillon" <> wrote in message
    > news:...
    >> Do you get an error?
    >>
    >> Break it into pieces...hard-code SelectedValue etc until you find why it
    >> isn't working
    >>
    >> "CK" <> wrote in message
    >> news:qxNag.28618$...
    >>> Hi All,
    >>> I have a class and one property is an Enum. I am trying to persist the
    >>> DropDownList.SelectedValue to the class property.
    >>> I am using
    >>> job.ExpRelated =
    >>> Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >>>
    >>> but it doesn't build. Any ideas anyone?
    >>>
    >>> Thanks All,
    >>>
    >>> ~CK
    >>>
    >>>

    >>
    >>

    >
    >
    Jeff Dillon, May 18, 2006
    #4
  5. CK

    Rajib Guest

    Try this:
    job.ExpRelated = (ExpRelated)
    Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);

    Hope that works.

    - Rajib


    "CK" <> wrote in message
    news:qxNag.28618$...
    > Hi All,
    > I have a class and one property is an Enum. I am trying to persist the
    > DropDownList.SelectedValue to the class property.
    > I am using
    > job.ExpRelated =
    > Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >
    > but it doesn't build. Any ideas anyone?
    >
    > Thanks All,
    >
    > ~CK
    >
    >
    Rajib, May 18, 2006
    #5
  6. CK

    CK Guest

    Well this works.
    job.ExpRelated = ExperienceRelated.Directly;

    I basically wanted to grab the value from the dropdown and cast it as an
    Enum.

    Any ideas? I can't give you an error as it doesn't compile. The compiler
    gives me a typecasting error.

    E:\Web Projects\EmploymentSolution\Employment\AppEmploymentCtl.ascx.cs(390):
    Cannot implicitly convert type 'object' to
    'Employment.Library.ExperienceRelated'




    "Jeff Dillon" <> wrote in message
    news:...
    > Instead of ddlExpRelated.SelectedValue, hard-code a specific value.
    >
    > Did you copy this code? Beginners generally don't know about Enum's and
    > typeof...
    >
    > start with Job.ExpRelated = value
    >
    > then add pieces in one at a time to see where it's failing
    >
    > And post your error message
    >
    > Jeff
    >
    > "CK" <> wrote in message
    > news:1TNag.28622$...
    >>I am sorry. I am a beginner. I am not quite sure what you mean.
    >> How do I do that?
    >>
    >> "Jeff Dillon" <> wrote in message
    >> news:...
    >>> Do you get an error?
    >>>
    >>> Break it into pieces...hard-code SelectedValue etc until you find why it
    >>> isn't working
    >>>
    >>> "CK" <> wrote in message
    >>> news:qxNag.28618$...
    >>>> Hi All,
    >>>> I have a class and one property is an Enum. I am trying to persist the
    >>>> DropDownList.SelectedValue to the class property.
    >>>> I am using
    >>>> job.ExpRelated =
    >>>> Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >>>>
    >>>> but it doesn't build. Any ideas anyone?
    >>>>
    >>>> Thanks All,
    >>>>
    >>>> ~CK
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    CK, May 18, 2006
    #6
  7. CK

    Rajib Guest

    Your initial statement is basically converting it to an object. Assuming the
    assignment works correctly all you needed to do a type cast to
    ExperienceRelated.

    Updated statement:

    job.ExpRelated = (ExperienceRelated)
    Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);

    "CK" <> wrote in message
    news:KkOag.28638$...
    > Well this works.
    > job.ExpRelated = ExperienceRelated.Directly;
    >
    > I basically wanted to grab the value from the dropdown and cast it as an
    > Enum.
    >
    > Any ideas? I can't give you an error as it doesn't compile. The compiler
    > gives me a typecasting error.
    >
    > E:\Web
    > Projects\EmploymentSolution\Employment\AppEmploymentCtl.ascx.cs(390):
    > Cannot implicitly convert type 'object' to
    > 'Employment.Library.ExperienceRelated'
    >
    >
    >
    >
    > "Jeff Dillon" <> wrote in message
    > news:...
    >> Instead of ddlExpRelated.SelectedValue, hard-code a specific value.
    >>
    >> Did you copy this code? Beginners generally don't know about Enum's and
    >> typeof...
    >>
    >> start with Job.ExpRelated = value
    >>
    >> then add pieces in one at a time to see where it's failing
    >>
    >> And post your error message
    >>
    >> Jeff
    >>
    >> "CK" <> wrote in message
    >> news:1TNag.28622$...
    >>>I am sorry. I am a beginner. I am not quite sure what you mean.
    >>> How do I do that?
    >>>
    >>> "Jeff Dillon" <> wrote in message
    >>> news:...
    >>>> Do you get an error?
    >>>>
    >>>> Break it into pieces...hard-code SelectedValue etc until you find why
    >>>> it isn't working
    >>>>
    >>>> "CK" <> wrote in message
    >>>> news:qxNag.28618$...
    >>>>> Hi All,
    >>>>> I have a class and one property is an Enum. I am trying to persist the
    >>>>> DropDownList.SelectedValue to the class property.
    >>>>> I am using
    >>>>> job.ExpRelated =
    >>>>> Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >>>>>
    >>>>> but it doesn't build. Any ideas anyone?
    >>>>>
    >>>>> Thanks All,
    >>>>>
    >>>>> ~CK
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Rajib, May 18, 2006
    #7
  8. CK

    Jeff Dillon Guest

    You just gave me the error. Do as the error suggests?

    "CK" <> wrote in message
    news:KkOag.28638$...
    > Well this works.
    > job.ExpRelated = ExperienceRelated.Directly;
    >
    > I basically wanted to grab the value from the dropdown and cast it as an
    > Enum.
    >
    > Any ideas? I can't give you an error as it doesn't compile. The compiler
    > gives me a typecasting error.
    >
    > E:\Web
    > Projects\EmploymentSolution\Employment\AppEmploymentCtl.ascx.cs(390):
    > Cannot implicitly convert type 'object' to
    > 'Employment.Library.ExperienceRelated'
    >
    >
    >
    >
    > "Jeff Dillon" <> wrote in message
    > news:...
    >> Instead of ddlExpRelated.SelectedValue, hard-code a specific value.
    >>
    >> Did you copy this code? Beginners generally don't know about Enum's and
    >> typeof...
    >>
    >> start with Job.ExpRelated = value
    >>
    >> then add pieces in one at a time to see where it's failing
    >>
    >> And post your error message
    >>
    >> Jeff
    >>
    >> "CK" <> wrote in message
    >> news:1TNag.28622$...
    >>>I am sorry. I am a beginner. I am not quite sure what you mean.
    >>> How do I do that?
    >>>
    >>> "Jeff Dillon" <> wrote in message
    >>> news:...
    >>>> Do you get an error?
    >>>>
    >>>> Break it into pieces...hard-code SelectedValue etc until you find why
    >>>> it isn't working
    >>>>
    >>>> "CK" <> wrote in message
    >>>> news:qxNag.28618$...
    >>>>> Hi All,
    >>>>> I have a class and one property is an Enum. I am trying to persist the
    >>>>> DropDownList.SelectedValue to the class property.
    >>>>> I am using
    >>>>> job.ExpRelated =
    >>>>> Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >>>>>
    >>>>> but it doesn't build. Any ideas anyone?
    >>>>>
    >>>>> Thanks All,
    >>>>>
    >>>>> ~CK
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Jeff Dillon, May 18, 2006
    #8
  9. CK

    CK Guest

    I get:
    Object reference not set to an instance of an object

    when I use:
    (ExperienceRelated)Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);

    and I get:
    E:\Web Projects\EmploymentSolution\Employment\AppEmploymentCtl.ascx.cs(390):
    The type or namespace name 'ExpRelated' could not be found (are you missing
    a using directive or an assembly reference?)

    when I use:
    (ExpRelated)Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);



    Any other ideas anyone? I know this should be doable.

    Thanks,

    ~CK





    "Rajib" <> wrote in message
    news:...
    > Try this:
    > job.ExpRelated = (ExpRelated)
    > Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >
    > Hope that works.
    >
    > - Rajib
    >
    >
    > "CK" <> wrote in message
    > news:qxNag.28618$...
    >> Hi All,
    >> I have a class and one property is an Enum. I am trying to persist the
    >> DropDownList.SelectedValue to the class property.
    >> I am using
    >> job.ExpRelated =
    >> Enum.ToObject(typeof(ExperienceRelated),ddlExpRelated.SelectedValue);
    >>
    >> but it doesn't build. Any ideas anyone?
    >>
    >> Thanks All,
    >>
    >> ~CK
    >>
    >>

    >
    >
    CK, May 18, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesse
    Replies:
    3
    Views:
    1,222
    DudeGuy
    Jul 24, 2003
  2. Tom Jorgenson
    Replies:
    3
    Views:
    7,009
  3. gu4y
    Replies:
    4
    Views:
    6,737
    mngates
    Jan 13, 2010
  4. Sudhir

    Dropdownlist.SelectedValue ISSUE

    Sudhir, Feb 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    454
    Scott Mitchell [MVP]
    Feb 26, 2004
  5. Thomas Kern
    Replies:
    1
    Views:
    400
    =?Utf-8?B?YWxhc3Bpbg==?=
    Nov 9, 2004
Loading...

Share This Page