---
title: "Populating drop down list from the database"  
description: "Populating drop down list from the database"  
author: "Anonymous User"  
published: 2014-11-17  
updated: 2014-11-17  
canonical: https://www.mindstick.com/forum/12622/populating-drop-down-list-from-the-database  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Populating drop down list from the database

I used this [c# code](https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-code) to [add items](https://www.mindstick.com/forum/160381/how-to-add-items-to-a-list-collection-in-c-sharp) in [dropdownlist](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework)(ddlSub) from the [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) sub_info. But what I want is to [add the value](https://www.mindstick.com/forum/159/be-add-the-value-in-dropdown-list) of the items in dropdownlist(ddlSub) from the same table which also has a [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) named sub_id of [datatype](https://www.mindstick.com/forum/160266/explain-the-datatype-data-annotation-and-its-significance-in-data-entry-and-display) [varchar](https://www.mindstick.com/forum/161878/what-is-the-difference-between-nvarchar-and-varchar)(50).

```
private void bind_ddlSub(){     ddlSub.Items.Insert(0, "-Choose-");    datatable_object = methodClassFunc.getData("select sub_name from sub_info");    for (int i = 0; i <= datatable_object.Rows.Count - 1; i++)    {        ddlSub.Items.Add(Convert.ToString(datatable_object.Rows[i]["sub_name"]));    }}
```

## Replies

### Reply by Sumit Kesarwani

Hi Jay, \

You can use the ListItem object to add text and [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) for a dropdownlist item.

```
string subname =datatable_object.Rows[i]["sub_name"];string subid = datatable_object.Rows[i]["sub_id"];ddlSub.Items.Add(new ListItem(subname,subid));Or you can bind your datasource like this:ddlSub.DataSource = datatable_object;ddlSub.DataTextField = "sub_name";ddlSub.DataValueField = "sub_id";ddlSub.DataBind();
```


---

Original Source: https://www.mindstick.com/forum/12622/populating-drop-down-list-from-the-database

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
