本文整理汇总了C#中System.Web.UI.WebControls.DropDownList.DataBind方法的典型用法代码示例。如果您正苦于以下问题:C# DropDownList.DataBind方法的具体用法?C# DropDownList.DataBind怎么用?C# DropDownList.DataBind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.DropDownList
的用法示例。
在下文中一共展示了DropDownList.DataBind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
Trace.Write("starting Page Load");
if (Session["TableDataSet"] != null)
{
DataSet tds = Session["TableDataSet"] as DataSet;
Trace.Write(tds.ToString());
var tablenames = GetTablenames(tds.Tables);
sheetCombo.DataSource = tablenames;
sheetCombo.DataBind();
GridView1.DataSource = tds.Tables[sheetCombo.SelectedIndex];
GridView1.DataBind();
//columnCombo.DataSource = tds.Tables[sheetCombo.SelectedIndex].Columns;
//columnCombo.DataBind();
//Get the list of columns to be assigned from DB
foreach (DataColumn columnName in tds.Tables[sheetCombo.SelectedIndex].Columns)
{
Label myLabel = new Label();
myLabel.Text = columnName.ToString();
myLabel.ID = columnName.ToString() +"label";
myLabel.Width = 120;
myLabel.Height = 28;
columnPanel.Controls.Add(myLabel);
DropDownList myDropDownList = new DropDownList();
myDropDownList.ID = columnName.ToString() + "combo";
//Remove this once table lookup in place.
myDropDownList.DataSource = tds.Tables[sheetCombo.SelectedIndex].Columns;
myDropDownList.DataBind();
//need to load data to control. Following code is for proof of concept.
Trace.Warn("starting DB read");
myDropDownList.DataSource = dsColumn;
myDropDownList.Height = 28;
myDropDownList.DataValueField = "COLUMNCONFIG_IDX";
myDropDownList.DataTextField = "COLUMN_NAME";
myDropDownList.DataBind();
columnPanel.Controls.Add(myDropDownList);
//columnPanel.Controls.Add(new LiteralControl("<br/>"));
}
}
}
catch (Exception ex)
{
Trace.Warn("error caught. " + ex.Message);
//catch error code
}
}
示例2: BindDropDownDataSource
/// <summary>
/// Set the selected value of a drop down.
/// </summary>
/// <param name="dropDownList"></param>
/// <param name="data"></param>
public static void BindDropDownDataSource(DropDownList dropDownList, ICollection data)
{
try
{
dropDownList.DataSource = data;
dropDownList.DataBind();
}
catch (ArgumentOutOfRangeException)
{
dropDownList.Items.Clear();
dropDownList.SelectedValue = null;
dropDownList.DataSource = data;
dropDownList.DataBind();
}
}
示例3: fillDropdownlistWithDT
public void fillDropdownlistWithDT(DropDownList ddl, DataTable dt, String id, String title)
{
ddl.DataSource = dt;
ddl.DataValueField = id;
ddl.DataTextField = title;
ddl.DataBind();
}
示例4: BindDropDownList
/// <summary>
/// 绑定一个DropDownList
/// </summary>
/// <param name="ddl">DropDownList实例</param>
/// <param name="ddlText">DropDownList显示文本</param>
/// <param name="ddlValue">DropDownList值</param>
/// <param name="className">类名称</param>
/// <param name="methodName">要调用的方法</param>
/// <param name="parameterValue">参数值</param>
public static void BindDropDownList(DropDownList ddl, string ddlText, string ddlValue, object className, string methodName, string parameterValue)
{
ddl.DataSource = CallMethod(className, methodName, parameterValue);
ddl.DataTextField = ddlText;
ddl.DataValueField = ddlValue;
ddl.DataBind();
}
示例5: AddEditor
protected override Control AddEditor(Control container)
{
IEnumerable<ProductBrief> productBriefs;
try
{
ShopperApiClientHelperForN2Admin.AssureLimitedAuthentication(false);
productBriefs = Context.Current.Container.Resolve<ICatalogApi>().GetProductBriefsAsync().Result;
}
catch
{ // TODO - better error handling, e.g. show an input box
productBriefs = new ProductBrief[0];
}
// here we create the editor control and add it to the page
var list = new DropDownList
{
ID = Name,
DataTextField = "IdAndName",
DataValueField = "Id",
DataSource = productBriefs
};
list.DataBind();
container.Controls.Add(list);
return list;
}
示例6: BindDropdownlist
public void BindDropdownlist(DropDownList dropdownlist, IEnumerable dataSource, string textField, string valueField)
{
dropdownlist.DataTextField = "TextField";
dropdownlist.DataValueField = "ValueField";
dropdownlist.DataSource = dataSource;
dropdownlist.DataBind();
}
示例7: setDropdownList
public void setDropdownList(DropDownList ddl, DataSet ds, string display, string value)
{
ddl.DataSource = ds;
ddl.DataTextField = display;
ddl.DataValueField = value;
ddl.DataBind();
}
示例8: SetDatasetToDropDownList
//public void SetCheckBoxListForMemberList(List<Design> oLists, CheckBoxList oBoxList)
//{
// foreach (Design oList in oLists)
// {
// ListItem oItem = new ListItem();
// oItem.Text = oList.ColumnName.ToString();
// oBoxList.Items.Add(oItem);
// }
//}
public void SetDatasetToDropDownList(DataSet oDS, DropDownList oDDL, String TextField, String IDField)
{
oDDL.DataSource = oDS;
oDDL.DataTextField = TextField;
oDDL.DataValueField = IDField;
oDDL.DataBind();
}
示例9: BindContactTitle
public void BindContactTitle(DropDownList _ddlContactTitles)
{
ContactServiceClient contactService = null;
try
{
contactService = new ContactServiceClient();
CollectionRequest collectionRequest = new CollectionRequest();
collectionRequest.StartRow = 0;
TitleSearchCriteria titleCriteria = new TitleSearchCriteria();
TitleSearchReturnValue titleReturnValue = contactService.TitleSearch(_logonSettings.LogonId, collectionRequest, titleCriteria);
if (titleReturnValue.Title != null)
{
_ddlContactTitles.DataSource = titleReturnValue.Title.Rows;
_ddlContactTitles.DataTextField = "TitleId";
_ddlContactTitles.DataValueField = "TitleId";
_ddlContactTitles.DataBind();
}
AddDefaultToDropDownList(_ddlContactTitles);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (contactService != null)
{
if (contactService.State != System.ServiceModel.CommunicationState.Faulted)
contactService.Close();
}
}
}
示例10: BindDDL
protected void BindDDL(DropDownList ddl,Dictionary<string,string> dict)
{
ddl.DataSource = dict;
ddl.DataTextField = "Value";
ddl.DataValueField = "Key";
ddl.DataBind();
}
示例11: LlenarCombo_Web
public bool LlenarCombo_Web( DropDownList Generico )
{
if ( ! Validar() )
return false;
clsConexionBD objConexionBd = new clsConexionBD( strApp );
try
{
objConexionBd.SQL = strSQL;
if ( ! objConexionBd.LlenarDataSet( false ) )
{
strError = objConexionBd.Error;
objConexionBd.CerrarCnx();
objConexionBd = null;
return false;
}
Generico.DataSource = objConexionBd.DataSet_Lleno.Tables[0];
Generico.DataValueField = strCampoID;
Generico.DataTextField = strCampoTexto;
Generico.DataBind();
objConexionBd.CerrarCnx();
objConexionBd = null;
return true;
}
catch (Exception ex)
{
strError = ex.Message;
return false;
}
}
示例12: PopulateDropDownList
private void PopulateDropDownList(DropDownList pdlist, DataTable pDataTable, String pstrDataMember, String pstrDataValueField)
{
pdlist.DataSource = pDataTable;
pdlist.DataTextField = pstrDataMember;
pdlist.DataValueField = pstrDataValueField;
pdlist.DataBind();
}
示例13: load_data_to_cbo_bo_tinh
public static void load_data_to_cbo_bo_tinh(
eTAT_CA ip_e_tat_ca
, DropDownList ip_obj_cbo_bo_tinh)
{
US_DM_DON_VI v_us_dm_don_vi = new US_DM_DON_VI();
DS_DM_DON_VI v_ds_dm_don_vi = new DS_DM_DON_VI();
//v_us_dm_don_vi.FillDataset(v_ds_dm_don_vi, "where ID_LOAI_DON_VI = " + ID_LOAI_DON_VI.BO_TINH);
string v_str_user_name = HttpContext.Current.Session[SESSION.UserName].ToString();
v_us_dm_don_vi.FillDataset(
v_ds_dm_don_vi
, ID_LOAI_DON_VI.BO_TINH
, CONST_QLDB.ID_TAT_CA
, CONST_QLDB.ID_TAT_CA
, v_str_user_name);
ip_obj_cbo_bo_tinh.DataSource = v_ds_dm_don_vi.DM_DON_VI;
ip_obj_cbo_bo_tinh.DataTextField = DM_DON_VI.TEN_DON_VI;
ip_obj_cbo_bo_tinh.DataValueField = DM_DON_VI.ID;
ip_obj_cbo_bo_tinh.DataBind();
if (ip_e_tat_ca == eTAT_CA.YES)
{
ip_obj_cbo_bo_tinh.Items.Insert(0, new ListItem(CONST_QLDB.TAT_CA, CONST_QLDB.ID_TAT_CA.ToString()));
}
}
示例14: BindListInternal
internal static void BindListInternal(DropDownList comboBox, object value, IEnumerable listSource, string textField, string valueField)
{
if (comboBox != null)
{
string selectedValue = !comboBox.Page.IsPostBack ? Convert.ToString(value) : comboBox.SelectedValue;
if (listSource is Dictionary<string, string>)
{
var items = listSource as Dictionary<string, string>;
foreach (var item in items)
{
comboBox.Items.Add(new ListItem(item.Key, item.Value));
}
}
else
{
comboBox.DataTextField = textField;
comboBox.DataValueField = valueField;
comboBox.DataSource = listSource;
comboBox.DataBind();
}
//Reset SelectedValue
comboBox.Select(selectedValue);
}
}
示例15: SetDataSource
/// <summary>
/// Utility function to set data source of a drop down control.
/// </summary>
/// <param name="dropDown"></param>
/// <param name="dataSource"></param>
public static void SetDataSource(DropDownList dropDown, IList dataSource)
{
dropDown.DataSource = dataSource;
dropDown.DataTextField = "DisplayMember";
dropDown.DataValueField = "ValueMember";
dropDown.DataBind();
}