By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

DropDownList.SelectedValue

P: n/a
CK
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK
May 17 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Do you get an error?

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

"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK

May 17 '06 #2

P: n/a
CK
I am sorry. I am a beginner. I am not quite sure what you mean.
How do I do that?

"Jeff Dillon" <je********@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...
Do you get an error?

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

"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK


May 17 '06 #3

P: n/a
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" <c_**********@hotmail.com> wrote in message
news:1T*******************@newssvr11.news.prodigy. com...
I am sorry. I am a beginner. I am not quite sure what you mean.
How do I do that?

"Jeff Dillon" <je********@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...
Do you get an error?

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

"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK



May 17 '06 #4

P: n/a
Try this:
job.ExpRelated = (ExpRelated)
Enum.ToObject(typeof(ExperienceRelated),ddlExpRela ted.SelectedValue);

Hope that works.

- Rajib
"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK

May 17 '06 #5

P: n/a
CK
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\AppEmployme ntCtl.ascx.cs(390):
Cannot implicitly convert type 'object' to
'Employment.Library.ExperienceRelated'


"Jeff Dillon" <je********@hotmail.com> wrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...
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" <c_**********@hotmail.com> wrote in message
news:1T*******************@newssvr11.news.prodigy. com...
I am sorry. I am a beginner. I am not quite sure what you mean.
How do I do that?

"Jeff Dillon" <je********@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...
Do you get an error?

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

"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK



May 17 '06 #6

P: n/a
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),ddlExpRela ted.SelectedValue);

"CK" <c_**********@hotmail.com> wrote in message
news:Kk*******************@newssvr11.news.prodigy. com...
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\AppEmployme ntCtl.ascx.cs(390):
Cannot implicitly convert type 'object' to
'Employment.Library.ExperienceRelated'


"Jeff Dillon" <je********@hotmail.com> wrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...
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" <c_**********@hotmail.com> wrote in message
news:1T*******************@newssvr11.news.prodigy. com...
I am sorry. I am a beginner. I am not quite sure what you mean.
How do I do that?

"Jeff Dillon" <je********@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...
Do you get an error?

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

"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
> 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),ddlExpRela ted.SelectedValue);
>
> but it doesn't build. Any ideas anyone?
>
> Thanks All,
>
> ~CK
>
>



May 17 '06 #7

P: n/a
You just gave me the error. Do as the error suggests?

"CK" <c_**********@hotmail.com> wrote in message
news:Kk*******************@newssvr11.news.prodigy. com...
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\AppEmployme ntCtl.ascx.cs(390):
Cannot implicitly convert type 'object' to
'Employment.Library.ExperienceRelated'


"Jeff Dillon" <je********@hotmail.com> wrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...
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" <c_**********@hotmail.com> wrote in message
news:1T*******************@newssvr11.news.prodigy. com...
I am sorry. I am a beginner. I am not quite sure what you mean.
How do I do that?

"Jeff Dillon" <je********@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...
Do you get an error?

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

"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
> 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),ddlExpRela ted.SelectedValue);
>
> but it doesn't build. Any ideas anyone?
>
> Thanks All,
>
> ~CK
>
>



May 17 '06 #8

P: n/a
CK
I get:
Object reference not set to an instance of an object

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

and I get:
E:\Web Projects\EmploymentSolution\Employment\AppEmployme ntCtl.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" <ra****@e-2-d.com> wrote in message
news:u8**************@TK2MSFTNGP03.phx.gbl...
Try this:
job.ExpRelated = (ExpRelated)
Enum.ToObject(typeof(ExperienceRelated),ddlExpRela ted.SelectedValue);

Hope that works.

- Rajib
"CK" <c_**********@hotmail.com> wrote in message
news:qx******************@newssvr11.news.prodigy.c om...
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),ddlExpRela ted.SelectedValue);

but it doesn't build. Any ideas anyone?

Thanks All,

~CK


May 18 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.