Common DropDownList Issue

written by Ryan Olshan on Saturday, December 17 2005

A common DropDownList issue I've seen on many forums and lists is about a DropDownList populating items 2x or not being able to get the selected value on postback when binding to a data source. This is due to the DropDownList having data bound to it again on postback before the form is processed. To prevent this, you will need to ensure that the DropDownList is only bound to data on the initial load of the page.

VB.NET
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
   If Not IsPostBack Then
      ' Code here to bind data to DropDownList
   End If
End Sub

C#
private void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      // Code here to bind data to DropDownList
   }
}

R

Kick this post on .NET Kicks

Similar Posts

  1. Getting the content of a GridView cell on edit
  2. VB.NET GridView Sorting/Paging w/o a DataSourceControl DataSource
  3. C# GridView Sorting/Paging w/o a DataSourceControl DataSource

Comments

  • Peter Brunone on on 12.17.2005 at 11:33 PM

    Peter Brunone avatar


    It's stuff like this that got me working on ELB in the first place :)

Post a comment