fill drop down list
How do i fill radio button list and dro开发者_如何学Cp downlist from database.
See http://msdn.microsoft.com/en-us/library/31723w77(v=VS.85).aspx
have a look at DataBinding and data boundable controls in MSDN. Your question like that it's so generic...
Get the record from datasource in datatable or dataset and bind with dropdownlist. For example:
DataTable dt = new DataTable();
dt = your query to return data as datatable;
dropdownlist.DataSource = dt;
dropdownlist.DataBind();
or create a common function like:
public static void BindDropDownList(DataTable _dt, System.Web.UI.WebControls.DropDownList _ddl, bool IsDIndex,string text)
{
try
{
_ddl.DataSource = _dt;
_ddl.DataBind();
if (IsDIndex == true)
{
_ddl.Items.Insert(0, new ListItem(text, "0"));
}
}
catch (Exception ex)
{
General.ErrorLog(ex.Message + " Stack Trace: " + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error, "General - BindDropDownList()");
}
}
精彩评论