Results 1 to 7 of 7

Thread: DropDownList SelectedIndex not changing

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    1

    DropDownList SelectedIndex not changing

    I have a webform with a databound DropDownList on it. After selecting an entry from the list and submitting the form, the SelectedIndex property still contains the default value rather than the value that I selected from the list. I have other similary configured webforms with databound DropDownLists and they all work as expected. The only differences are that the form that doesn't work contains a UserControl and the pull their data from different tables. Any Ideas?

  2. #2
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    The first thing that comes to mind is the possibility of re-binding the control when your page is reloaded. Where are you binding the DropDownList? And are you verifying that property "Page.IsPostBack = False" before executing the code to bind the control?
    Dr_Evil
    Senior Programmer
    VS6 EE
    VS.NET EA

  3. #3
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471
    I have the same problem.
    I did the binding in control's properties window. can somebody tell how to make it work?

  4. #4
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471
    hi,demtet,
    can you tell how you made your other forms work? thanks.

  5. #5
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Only bind your data to the dropdownlist if Not page.ispostback=true. From then on the viewstate if the control will retain the list and it should highlight your chosen item.

    i.e.

    'Page Load event
    If not page.ispostback then
    BindData()
    End If

    Private Sub BindData
    'code to bind data to dropdownlist
    End Sub

  6. #6
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471
    thanks.

    another question:

    How to populate date to datagrid programly? I want to fill the grid by a query result.

  7. #7
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    VB Code:
    1. Dim sql As String = "SELECT * FROM DPSlisting"
    2.         Dim ConnStr As String = "xxxxconn string xxxxx"
    3.         Dim mySQLconn As New SqlConnection(ConnStr)
    4.         mySQLconn.Open()
    5.         Dim mysqladapter As New SqlDataAdapter()
    6.         mysqladapter.SelectCommand = New SqlCommand(sql, mySQLconn)
    7.         Dim myDS As New DataSet()
    8.         mysqladapter.Fill(myDS)
    9.         mySQLconn.Close()
    10.  
    11.         ddlListing.DataSource = myDS
    12.         ddlListing.DataTextField = ("ReportDate")
    13.         ddlListing.DataBind()

    hope that helped?
    Soylent Green tastes like chicken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width