Adding a list item to the System.Web.UI.WebControls.DropDownList

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Adding a list item to the System.Web.UI.WebControls.DropDownList

    I was wondering if there was any way to add a blank list
    item control to the beginning of the
    System.Web.UI.WebControls.DropDownList's datasource after
    the control's datasource has been specified.

    Here's my code right now:

    Dim oEmptyOption as New ListItem()

    'Assign datasource to delivery date type combobox
    cboDeliveryDateType.DataSource = oDsDeliveryDateType.Tables
    ("DataTable")
    cboDeliveryDateType.DataTextField =
    oDsDeliveryDateType.Tables("DataTable").Columns.It em
    ("Display_Name").ToString()
    cboDeliveryDateType.DataValueField =
    oDsDeliveryDateType.Tables("DataTable").Columns.It em
    ("Delivery_Date_Type_ID").ToString()
    cboDeliveryDateType.DataBind()

    'Add empty option field
    cboDeliveryDateType.Items.Add(oEmptyOption) 'adds to the
    end of the list.

    Currently, I am able to add the blank item at the end of
    the controls Item's list, and select it as the default
    selected item, but it appears as the last item in the drop
    down list. I want to have it at the beginning of the list.
    Any suggestions would be greatly appreciated.

    Thanks,

    Chris...
    Chris Guest

  2. Similar Questions and Discussions

    1. add reference for System.Web.UI.webcontrols which dll?
      Which dll should i add a reference to to get this. i've added System.Web.UI, but this does not give me WebControls. thanks kes
    2. can't set the selected item of the dropdownlist
      I generate template columns in datagrid dynamic and I want dropdownlist in the EditItemTemplate, I did it But I can't set the selected item of...
    3. Change style of a single row of the item list of datagrid, based on a field value of current item...
      Sorry for the long subject guys, but I don't know how better I can resume the matter... Anyway, I have my datagrid showing items of an order. I...
    4. System.Web.UI.WebControls Namespace
      Does anyone have any sample code on code on creating tables/rows and cells using above namespace and adding checkbox controls to my cells? ...
    5. The type System.Web.UI.WebControls.TextBox in Assembly System.Web...error
      I've been getting this error every since I installed InstallSqlState to handle my viewState Sessions. it only happens on 1 section of my asp.net...
  3. #2

    Default Re: Adding a list item to the System.Web.UI.WebControls.DropDownList

    Chris:

    Try using Insert instead of Add - it takes the index to add the ListItem to,
    and the ListItem object you want to add:

    cboDeliveryDateType.Items.Insert(0, oEmptyOption)

    HTH
    --
    Elliot M. Rodriguez, MCSD
    *** It would take 227 cans of Mountain Dew to kill me***



    "Chris" <chrisb@papex.com> wrote in message
    news:80f701c3505b$fa023300$7d02280a@phx.gbl...
    > I was wondering if there was any way to add a blank list
    > item control to the beginning of the
    > System.Web.UI.WebControls.DropDownList's datasource after
    > the control's datasource has been specified.
    >
    > Here's my code right now:
    >
    > Dim oEmptyOption as New ListItem()
    >
    > 'Assign datasource to delivery date type combobox
    > cboDeliveryDateType.DataSource = oDsDeliveryDateType.Tables
    > ("DataTable")
    > cboDeliveryDateType.DataTextField =
    > oDsDeliveryDateType.Tables("DataTable").Columns.It em
    > ("Display_Name").ToString()
    > cboDeliveryDateType.DataValueField =
    > oDsDeliveryDateType.Tables("DataTable").Columns.It em
    > ("Delivery_Date_Type_ID").ToString()
    > cboDeliveryDateType.DataBind()
    >
    > 'Add empty option field
    > cboDeliveryDateType.Items.Add(oEmptyOption) 'adds to the
    > end of the list.
    >
    > Currently, I am able to add the blank item at the end of
    > the controls Item's list, and select it as the default
    > selected item, but it appears as the last item in the drop
    > down list. I want to have it at the beginning of the list.
    > Any suggestions would be greatly appreciated.
    >
    > Thanks,
    >
    > Chris...

    Elliot M. Rodriguez Guest

  4. #3

    Default Re: Adding a list item to the System.Web.UI.WebControls.DropDownList

    Elliot,

    Dead on. Thank you. Problem solved.

    Thanks,

    Chris...



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Chris Barrow Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139