Hi All,
I currently have two dropdown lists which are bound to a SQL DataSource. The two controls have the following properties set:
- AppendDataBoundItems = True
- AutoPostBack = False
- CausesValidation = True
When a Button Click Event fires, the dropdown lists default to the first value in the SQL DataSource.
I've removed the DataBinding and manually added items and upon clicking a button, the value originally selected in the dropdown list remains as is.
Below is the code I am using to bind one of the drop down lists.
VB Code:
Protected Sub BindAuthorityDDL()
Me.ddlAuthority.Items.Clear()
Try
Using da As New SqlDataAdapter("SELECT Activity, TimeUnit FROM tblATU WHERE FieldName = 'ddlAuthority' ORDER BY Activity ASC", ConfigurationManager.ConnectionStrings("DEEstimatorConnectionString").ToString())
Dim dt As New DataTable
da.Fill(dt)
da.Dispose()
Me.ddlAuthority.DataSource = dt
Me.ddlAuthority.DataTextField = "Activity"
Me.ddlAuthority.DataValueField = "TimeUnit"
Me.ddlAuthority.DataBind()
End Using
Catch ex As Exception
End Try
End Sub
VB Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindAuthorityDDL()
End If
End Sub