ViewState of DropdownLists (In 2005)

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
I'm using dropdownlists for the user to select an item which is then saved into the database. I'm sure this WAS working when i originally tested it, now i've come back to it (was using the frame to set up test data for a later frame) and its not working. (It just selects the first item).

I've even tried the below, which isnt working either.

Visual Basic:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label11.Text = ddownRoles.SelectedIndex.ToString 
        'also tried selectedvalue, which as i'm sure you know displays the samething
    End Sub

I'm using .Net 2005, i've checked that the 'EnableViewState' is set to true. I'm guessing this has something to do with the button doing a postback. After the label has been changed (to show the first item, not the selected one), the dropdownlist shows the first item again.

Does anybody know what i've done to display the viewstate memory?

Thanks.
 
How are you populating the list? If you are manually loading data or databinding in the page_load then this will lose the selection, make sure you only populate the list on the initial page_load and not for any post back events.
 
I'm calling the procedure to populate the in the page_load, but its wrapped in a "if not ispostback".

I think i've solved it by setting the dropdownlists to autopostback, but i'm not sure if thats the 'best' way to do this.

Thanks for the reply though :)
 
Back
Top