Skip to content

How to Set the Default Value of a DropDownList in an ASP.NET Page

Updated: at 11:17 PM

(Using Membership ObjectDataSource From MSDN Article)

I'm doing a project where I have lots of DropDownList's on a page and want a simple way to set the initial values based on some known value.  The DropDownLists are retrieved using ObjectDataSource but I don't want the first value displayed.  I wrestled some with how to do this using page_load or page_prerender but didn't come up with good solutions.  I did finally
decide that programming the databound event of the dropdownlist was probably the best way to go.

The solution is pasted below.  The MembershipUtilities.MembershipODS c# code can be downloaded from MSDN or on my web site at the following location.

<%@ Page Language=”C#” %>
<!DOCTYPE html PUBLIC-//W3C//DTD XHTML 1.0 Transitional//EN>

<script runat=”server> protected void DropDownListUser_DataBound(object sender, EventArgs e)

    DropDownListUser.SelectedIndex =


<html xmlns=”> <head runat=”server> <title>DropDownList Initialize</title> </head> <body> <form id=”form1runat=”server> <div> <asp:DropDownList ID=”DropDownListUserrunat=”serverDataSourceID=”ObjectDataSourceUserDataTextField=”UserNameDataValueField=”UserNameOnDataBound=”DropDownListUser_DataBound> </asp:DropDownList> <asp:ObjectDataSource ID=”ObjectDataSourceUserrunat=”serverSelectMethod=”GetMembersTypeName=”MembershipUtilities.MembershipUserODS> <SelectParameters> <asp:Parameter Name=”sortDataType=”String/> </SelectParameters> </asp:ObjectDataSource> </div> </form> </body> </html>