ASP.NET: DropDownList: Dynamically add Item from Database

  1. Execute Select command and return the data into DataTable
  2. DataTable
    1. Declare a DataTable variable DataTable dt
    2. Loop for Number of Rows: dt.Rows.Count
    3. Read value from DataTable: string str= dt.Rows[“Column_Name”]
  3. Add item into DropDownList: ddl.Items.Add(str);
 
DataTable dt = Utilities.GetCurrency(); //it returns DataTable
for (int i = 0; i < dt.Rows.Count; i++)
{
       stringstr=Convert.ToString(dt.Rows[i][“CURR_Currency_Name”]);
       currencyDropDownList.Items.Add(str);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s