insert "Select..." to dropdownlist

Posted on 2011-05-09
Last Modified: 2012-05-11

How can I insert initial value "Select..." to dropdownlist?
1. Dropdownlist is in Masterpage, contentplaceholder

For each ctrl as control in Form.controls

 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).DataSource = Me.SqlDataSource1
 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).Items.Insert(0, "Select...")    <<< this does not help
 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).DataTextField = "columnname"
 DirectCast(ctrl.FindControl("DropDownList" & y), DropDownList).DataBind()

Question by:VBdotnet2005
    LVL 29

    Accepted Solution


    Set the AppendDataBoundItems attribute to true and add the default listitem in the aspx :

    <asp:DropDownList id="list" runat="server" DataSourceID="dataSource" DataTextField="Name" DataValueField="id" AppendDataBoundItems="true" ><asp:ListItem Text="Select..." Value=0 /></asp:DropDownListItem>

    LVL 14

    Assisted Solution

    another way is,

    after assigning datasource and calling Databind, add this line

    Dropdownlist.Items.Insert(0, New ListItem("<<--Select-->>", ""))

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now