Sunday, 14 April 2013

DropDownList: Dynamically add Item from Database ASP.NET C#

  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++)
{
       string str=Convert.ToString(dt.Rows[i]["CURR_Currency_Name"]);
       currencyDropDownList.Items.Add(str);
}

No comments:

Post a Comment