There are a lot ways to set the default value for a dropdownlist when it has been databinded in an ASP.NET Page. I will list some of them and point out the pros and cons.
Way #1 (recommended way):
In an ASP.NET page, if the DropDownList web control (here I call dropdownExample) has an datasource (sqldatasource or objectdatasource), and when it is data binding you can define the following:
Protected Sub dropdownExample_DataBound(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dropdownExample.DataBound
‘set the default value for the drop downMe.dropdownExample.SelectedIndex = Me.dropdownExample.Items.IndexOf ( Me.dropdownExample.Items.FindByValue ( ‘The Default Value’ ) )
End Sub
Blog Comments