views:

155

answers:

1

Hi I'm using visual studio 2008 with .net 3.5. I have an AccessDataSource that is linked to a access database. I have a dropdownlist that use the AccessDataSource. Everything was done with the wizard and everything was working just fine.

At the page load I decided to call the SelectedIndexChanged of my dropdownlist to update something with the selectedValue but to my suprise the selectedValue was an empty string.

To resolve the problem I put this in my page_load Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then

        ddlAnniversaire.DataBind()
        ddlAnniversaire_SelectedIndexChanged(Nothing, Nothing)
    End If

End Sub

If I don't put ddlAnniversaire.DataBind() the ddlAnniversaire.selectedValue is "" in my method. Why?
Normally when is the ddlAnniversaire.DataBind() called?

Thanks

+1  A: 

The DataBind() event occurs after the Page_Load and in the PreRender event of the Page Lifecycle (MSDN link).

Hope this helps, JP

Jonathan
Is it ok to call the DataBing() in the Page_Load has I did?Is it going to be called twice?
Joel
After some testing I found that sometimes it's called twice, but I can't isolate why.
Jonathan
To pre-select an item, you can just set the SelectedIndex of the DDL in the OnRender event of the page or handle the Load event of the DDL.
Jonathan
Thank you very much...!
Joel