Databound drop down list - initial value

后端 未结 8 1901
小蘑菇
小蘑菇 2020-12-24 03:21

How do I set the initial value of a databound drop down list in ASP.NET?

For instance, I want the values, but the first value to display should be -- Select One ---

8条回答
  •  不知归路
    2020-12-24 04:02

    Add an item and set its "Selected" property to true, you will probably want to set "appenddatabounditems" property to true also so your initial value isn't deleted when databound.

    If you are talking about setting an initial value that is in your databound items then hook into your ondatabound event and set which index you want to selected=true you will want to wrap it in "if not page.isPostBack then ...." though

    Protected Sub DepartmentDropDownList_DataBound(ByVal sender As Object, ByVal e As    System.EventArgs) Handles DepartmentDropDownList.DataBound
        If Not Page.IsPostBack Then
            DepartmentDropDownList.SelectedValue = "somevalue"
        End If
    End Sub
    

提交回复
热议问题