Tuesday, March 13, 2012

Should be simple...

I am new to asp.net... but this should be simple, yet it does not appear to
work. I must be doing something wrong.

I have a web form with a dropdown list. I have successfully populated it
with data from sql server using a datareader.

How do you reference the item that you selected in the dropdown list (after
you select it) ?

My dropdown list is called ddJob.

I tried to simply place the value I selected into a text box...

Within the ddJob_SelectedIndexChanged I tried...

Textbox1.Text=ddJob.SelectedValue

But nothing happens when I select a value form the dropdown list.... Why ?

Thanks !Rob wrote:

Quote:

Originally Posted by

I am new to asp.net... but this should be simple, yet it does not appear to
work. I must be doing something wrong.
>
I have a web form with a dropdown list. I have successfully populated it
with data from sql server using a datareader.
>
How do you reference the item that you selected in the dropdown list (after
you select it) ?
>
My dropdown list is called ddJob.
>
I tried to simply place the value I selected into a text box...
>
Within the ddJob_SelectedIndexChanged I tried...
>
Textbox1.Text=ddJob.SelectedValue
>
But nothing happens when I select a value form the dropdown list.... Why ?
>
Thanks !


Is the dropdownlist being rebound on each page load? If so, the data is
being lost. You need to put the binding code in something like:

if(!IsPostBack)
{
// code here
}
Hi Rob,

You are nearly doing everything right!
It seems you are missing one little thing.
Its called "AutoPostBack" and it needs to be set to true.
Its on the drop down list properties.

What this means is that when you change the selected index, it will
post the data back to the server immediately, rather than when a button
is clicked.

Try it out!

Steven
hello,
use this..
Textbox1.Text=ddJob..SelectedItem.Text
regards

Rob wrote:

Quote:

Originally Posted by

I am new to asp.net... but this should be simple, yet it does not appear to
work. I must be doing something wrong.
>
I have a web form with a dropdown list. I have successfully populated it
with data from sql server using a datareader.
>
How do you reference the item that you selected in the dropdown list (after
you select it) ?
>
My dropdown list is called ddJob.
>
I tried to simply place the value I selected into a text box...
>
Within the ddJob_SelectedIndexChanged I tried...
>
Textbox1.Text=ddJob.SelectedValue
>
But nothing happens when I select a value form the dropdown list.... Why ?
>
Thanks !


Steven,

Thank You very much ! It works now...

Rob

"Steven Nagy" <learndotnet@.hotmail.comwrote in message
news:1159436210.802225.302720@.e3g2000cwe.googlegro ups.com...

Quote:

Originally Posted by

Hi Rob,
>
You are nearly doing everything right!
It seems you are missing one little thing.
Its called "AutoPostBack" and it needs to be set to true.
Its on the drop down list properties.
>
What this means is that when you change the selected index, it will
post the data back to the server immediately, rather than when a button
is clicked.
>
Try it out!
>
Steven
>

0 comments:

Post a Comment