---
title: "Insert a ListItem to a DropDownList"  
description: "Insert a ListItem to a DropDownList"  
author: "Lillian Martin"  
published: 2015-05-27  
updated: 2015-05-27  
canonical: https://www.mindstick.com/forum/23267/insert-a-listitem-to-a-dropdownlist  
category: "c#"  
tags: ["dropdown", "list"]  
reading_time: 1 minute  

---

# Insert a ListItem to a DropDownList

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) an ListItem at the beginning of my [dropdownlist](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework). I don't know why this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is not working. It only adds the [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) information. I created a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) that [inherits](https://www.mindstick.com/interview/85/what-is-a-subclass) from DropDownList in [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) to customize my own dropdownlist.

```
public class MyDropDownList : DropDownList{        protected override void OnInit(EventArgs e)        {            base.OnInit(e);            this.BindItems();        }         private void BindItems()        {            this.Items.Clear();            this.DataSource = this.GetData();            this.DataValueField = "CompositePK";            this.DataTextField = "Description";            this.DataBind();            this.Items.Insert(0, new ListItem("-Select-", "-1"));        }}
```

## Replies

### Reply by Anonymous User

Your code calls DataBind() before the call to Insert(), when the list is still empty. DataBind() reads the control's source and generates the appropriate elements without monitoring any future changes.

You need to reverse the order of the calls:

this.Items.Insert(0, new ListItem("-1", "-Select-"));

this.DataBind();


---

Original Source: https://www.mindstick.com/forum/23267/insert-a-listitem-to-a-dropdownlist

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
