Default value for a dropdownlist

Results 1 to 2 of 2

Thread: Default value for a dropdownlist

  1. #1
    Join Date
    Dec 1969

    Default Default value for a dropdownlist

    Hi all in classic asp I was able to do this<BR>&#060;select name=Department&#062;<BR> &#060;option&#062;Select One&#060;/option&#062;<BR> &#060;%Loopping recordset here%&#062;<BR> &#060;option value=ObjRs("DepartmentID")&#062;ObjRs("Department Name")&#060;/option&#062;<BR> &#060;%Loop%&#062;<BR>&#060;/Select&#062;<BR><BR>Basically I want to have one default value to be Select One.<BR>and the rest is from the database.<BR>In Asp.Net I have this on my Page_Load Event<BR> ObjCmd = New SQLCommand(strDepartment, ObjConn)<BR> ObjDepartmentReader = ObjCmd.ExecuteReader()<BR> cbo_Department.DataSource = ObjDepartmentReader<BR> cbo_Department.DataBind()<BR>and on my form I have this<BR><BR>&#060;asp:dropdownlist ID="cbo_Department" DataTextField="DepartmentName" DataValueField="DepartmentID" class="form_item" runat="server" /&#062; <BR><BR>My Question is how can I add this Select One default value and binding the control with a datareader at the same time<BR><BR>Thanks,<BR>Duc

  2. #2
    Join Date
    Dec 1969

    Default This article may help

    Adding a Default ListItem in a Databound Listbox in ASP.NET <BR><BR><BR>In a previous article I showed how to use databinding to automagically populate an ASP.NET&#039;s listbox Web control with just a few lines of code. (If you&#039;ve not already read the past article, be sure to do so now.) I&#039;ve received a couple of feedback emails from folks since publishing the article asking how to add a default option to the listbox. That is, they want to add a listitem to the listbox, like: -- Please Choose an Option Below--. In this brief article we&#039;ll tackle this topic and more!

Posting Permissions

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