DropDown list issue

M

Manoj Paramu Das

DropDwonList.SelectedItem.Value returns only the first record value, no
matter when you select. any help would be appreciated.

Thanks Manoj
 
G

Guest

Question: Are you re-binding the dropdownlist control when you postback (for
example, in Page Load?)
If so, that will change the SelectedIndex. You can surround your
databinding code with the following:

If Not Page.IsPostBack Then
'Databind the control.
End If

Note that this won't work if you have ViewState disabled enabled (enabled is
the default). If you have ViewState disabled or have to rebind on every
postback (for some reason), then you can get the value of the selected item
and then set the DDL with the following:

'Databind the control
If Page.IsPostBack Then
MyDropDownList.SelectedValue = MyDropDownList.ClientId
End If

(Of course, change the control names to match ... )
 
M

Manoj Paramu Das

Thanks to both Eliyahu Goldin and J Sawyer, I was doing the most silly thing
of binding the drop down, each time the page was loading up.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top