1. Have a SqlCommand object returning a Datatable with the records you want to use.
2. use the dropdownliads datasource property to specify this table as datasource
3. Use the DataMember property to specify the exact column of the table you want for the dropdown.
Here is a small code snippet that could help.
public DataTable ExecuteSelectCommand(string CommandName)
{
SqlCommand cmd = null;
DataTable table = new DataTable();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = CommandName;
try
{
con.Open();
SqlDataAdapter da = null;
using (da = new SqlDataAdapter(cmd))
{
da.Fill(table);
}
con.Close();
}
catch (Exception ex)
{
throw;
}
finally
{
cmd.Dispose();
cmd = null;
}
return table;
}
public DataTable GetCategories()
{
return Functions.ExecuteSelectCommand("Select * from Categories");
}
drp.DataSource = GetCategories();
drp.DataTextField = "Category";
drp.DataValueField = "category";
drp.DataBind();