Tag Archive for 'dropdownlist'

How to set the default value of a data binding DropDownList easily with ASP.NET page

ASP.netThere 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 down

Me.dropdownExample.SelectedIndex = Me.dropdownExample.Items.IndexOf ( Me.dropdownExample.Items.FindByValue ( ‘The Default Value’ ) )
End Sub

Continue reading ‘How to set the default value of a data binding DropDownList easily with ASP.NET page’

Related posts



Get Adobe Flash playerPlugin by wpburn.com wordpress themes