本文整理汇总了C#中DropDownList类的典型用法代码示例。如果您正苦于以下问题:C# DropDownList类的具体用法?C# DropDownList怎么用?C# DropDownList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DropDownList类属于命名空间,在下文中一共展示了DropDownList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindIndustry
public static void BindIndustry(DropDownList industryDropDownList)
{
industryDropDownList.DataValueField = "CategoryID";
industryDropDownList.DataTextField = "CategoryName";
industryDropDownList.DataSource = BindIndusty(HttpContext.Current.Session["LCID"].ToString());
industryDropDownList.DataBind();
}
示例2: cargar_combo
private void cargar_combo(DropDownList combo,String textField, String valueField)
{
combo.DataTextField = textField;
combo.DataValueField = valueField;
combo.DataBind();
combo.SelectedIndex = 0;
}
示例3: InitListLoaiXe
public static void InitListLoaiXe(DropDownList ComboboxName)
{
string sql = string.Format(@"SELECT * FROM {0} tt
ORDER BY tt.{1}", LOAI_XE.sTableName, LOAI_XE.cl_LOAI_XE_ID);
DataTable dt = SQLConnectWeb.GetTable(sql, LOAI_XE.sTableName);
InitDropDownList(ComboboxName, dt, LOAI_XE.cl_LOAI_XE_ID, LOAI_XE.cl_TEN_LOAI);
}
示例4: fillUnidades
private void fillUnidades(DropDownList combo, int c)
{
combo.Enabled = false;
combo.Items.Clear();
combo.AppendDataBoundItems = true;
combo.DataSource = psvm.getAllUnidades();
combo.DataValueField = "UNI_COD";
combo.DataTextField = "UNI_NOM";
combo.DataBind();
if (combo.Items.Count > 0)
{
combo.Enabled = true;
cargo_comboUnidad_SelectedIndexChanged(combo, null);
}
else
{
combo.Enabled = false;
combo.Items.Add(new ListItem("--Ninguno--", ""));
cargo_comboArea.Enabled = false;
cargo_comboArea.Items.Clear();
cargo_comboArea.AppendDataBoundItems = true;
cargo_comboArea.Items.Add(new ListItem("--Ninguno--", ""));
cargo_comboArea.DataBind();
}
}
示例5: InicializaCombo
public static void InicializaCombo(DropDownList ddl)
{
ddl.Items.Clear();
ddl.DataValueField = "ID";
ddl.DataTextField = "Nombre";
ddl.Items.Add(new ListItem("Selecciona una opción:", "-1"));
}
示例6: AddStaticData
public static void AddStaticData(DropDownList ddlStatus, int nLanguageID)
{
switch (nLanguageID)
{
case 1:
ListItem all_v = new ListItem("--- Tất cả ---", "-1", true);
all_v.Selected = true;
ddlStatus.Items.Add(all_v);
ListItem active_v = new ListItem("Hoạt động", "1", true);
ddlStatus.Items.Add(active_v);
ListItem inactive_v = new ListItem("Không hoạt động", "0", true);
ddlStatus.Items.Add(inactive_v);
break;
case 2:
ListItem all_e = new ListItem("--- All ---", "-1", true);
all_e.Selected = true;
ddlStatus.Items.Add(all_e);
ListItem active_e = new ListItem("Active", "1", true);
ddlStatus.Items.Add(active_e);
ListItem inactive_e = new ListItem("Inactive", "0", true);
ddlStatus.Items.Add(inactive_e);
break;
case 3:
ListItem all_j = new ListItem("--- All ---", "-1", true);
all_j.Selected = true;
ddlStatus.Items.Add(all_j);
ListItem active_j = new ListItem("Active", "1", true);
ddlStatus.Items.Add(active_j);
ListItem inactive_j = new ListItem("Inactive", "0", true);
ddlStatus.Items.Add(inactive_j);
break;
}
}
示例7: Page_Init
// 动态创建控件
// 注意:这段代码需要每次加载页面都执行,因此不能放在 if(!IsPostBack) 逻辑判断中
protected void Page_Init(object sender, EventArgs e)
{
// 创建一个 FormRow 控件并添加到 Form2
FormRow row = new FormRow();
row.ID = "rowUser";
Form2.Rows.Add(row);
TextBox tbxUser = new TextBox();
tbxUser.ID = "tbxUserName";
tbxUser.Text = "";
tbxUser.Label = "用户名";
tbxUser.ShowLabel = true;
tbxUser.ShowRedStar = true;
tbxUser.Required = true;
row.Items.Add(tbxUser);
DropDownList ddlGender = new DropDownList();
ddlGender.ID = "ddlGender";
ddlGender.Label = "性别(自动回发)";
ddlGender.Items.Add("男", "0");
ddlGender.Items.Add("女", "1");
ddlGender.SelectedIndex = 0;
ddlGender.AutoPostBack = true;
ddlGender.SelectedIndexChanged += new EventHandler(ddlGender_SelectedIndexChanged);
row.Items.Add(ddlGender);
}
示例8: BindLeaderList
/// <summary>
/// Binds the leader list to the current user's calendar access list.
/// Inserts the user calendar for the selected user if it does not exist. This case would occur if
/// the current user does not have access to the selected user's calendar.
/// </summary>
/// <param name="list">The list of user calendars.</param>
/// <param name="selectedUserId">The selected user id.</param>
public static void BindLeaderList(DropDownList list, string selectedUserId)
{
if (list.Items.Count > 1) return; // already loaded
list.Items.Clear();
bool selectedUserInList = false;
List<UserCalendar> userCalendar = UserCalendar.GetCurrentUserCalendarList();
foreach (UserCalendar uc in userCalendar)
{
if (uc.AllowAdd.HasValue && uc.AllowAdd.Value) // == true
{
if (uc.UserId.ToUpper().Trim() == selectedUserId.ToUpper().Trim()) selectedUserInList = true;
ListItem listItem = new ListItem(uc.UserName, uc.CalUser.Id.ToString());
list.Items.Add(listItem);
}
}
UserCalendar suc = UserCalendar.GetUserCalendarById(selectedUserId);
if (suc != null)
{
//Verify that we have the exact right userid. i.e. 'ADMIN ' may be trimmed to 'ADMIN'
selectedUserId = suc.CalUser.Id.ToString();
if (!selectedUserInList)
{
ListItem newItem = new ListItem(suc.UserName, suc.CalUser.Id.ToString());
list.Items.Add(newItem);
}
}
ListItem selected = list.Items.FindByValue(selectedUserId);
if (selected == null)
{
selected = new ListItem(selectedUserId, selectedUserId);
list.Items.Add(selected);
}
list.SelectedIndex = list.Items.IndexOf(selected);
}
示例9: GridView2_RowUpdating
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList ddlevelForMultCh = (DropDownList)(GridView2.Rows[e.RowIndex].FindControl("ddlevelForMultCh"));
caseOfErr = (DropDownList)(GridView2.Rows[e.RowIndex].FindControl("ddForMultChoCaseOferror"));
e.NewValues.Add("caseOfError", caseOfErr.SelectedItem.ToString());
e.NewValues.Add("level", ddlevelForMultCh.SelectedItem.ToString());
}
示例10: Bind
/// <summary>
/// Metodo para llenar un DropdownList
/// </summary>
/// <param name="dropDownList"></param>
/// <param name="data"></param>
public void Bind(DropDownList dropDownList, IList data, string value, string text)
{
dropDownList.DataSource = data;
dropDownList.DataValueField = value;
dropDownList.DataTextField = text;
dropDownList.DataBind();
}
示例11: LocationSelectorWithOptions
public LocationSelectorWithOptions(
Page page,
bool empty,
DropDownList country,
DropDownList state,
DropDownList city,
DropDownList neighborhood,
DropDownList type,
CheckBox picturesonly)
:
base(page, empty, country, state, city, neighborhood)
{
mType = type;
mPicturesOnly = picturesonly;
if (!mPage.IsPostBack)
{
List<TransitPlaceType> types = new List<TransitPlaceType>();
if (InsertEmptySelection) types.Add(new TransitPlaceType());
types.AddRange(page.SessionManager.GetCollection<TransitPlaceType>(
(ServiceQueryOptions)null, page.SessionManager.PlaceService.GetPlaceTypes));
mType.DataSource = types;
mType.DataBind();
}
}
示例12: SeleccionarItemCombo
public static void SeleccionarItemCombo(ref DropDownList combo, string valor, string texto)
{
combo.ClearSelection();
if ((combo.Items.FindByValue(valor) == null))
combo.Items.Insert(0, new ListItem(texto, valor));
combo.Items.FindByValue(valor).Selected = true;
}
示例13: bindDropDownList
/// <summary>
/// bind DropDownList control
/// </summary>
/// <param name="ddl">DropDownList control need to be bound</param>
/// <param name="ds">data source</param>
/// <param name="flag">bind style. true for binding text and value; false for binding text only.</param>
public void bindDropDownList(DropDownList ddl, DataSet ds, bool flag)
{
if (ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
int count = dt.Rows.Count;
int index = 0;
while (index < count)
{
if (flag)
{
var li = new ListItem(dt.Rows[index][0].ToString().Trim(), dt.Rows[index][1].ToString().Trim());
ddl.Items.Add(li);
}
else
ddl.Items.Add(dt.Rows[index][0].ToString().Trim());
index++;
}
ddl.Enabled = true;
}
else
{
if (flag)
{
var li = new ListItem("Not Exist", "-1");
ddl.Items.Add(li);
}
else
ddl.Items.Add("Not Exist");
ddl.Enabled = false;
}
}
示例14: FillCustomersDDL
public static void FillCustomersDDL(string companyName, DropDownList ddl)
{
SqlDataReader sqlReader;
SqlConnection sqlConn = new SqlConnection(sConnection);
sqlConn.Open();
using (SqlCommand sqlComm = new SqlCommand())
{
sqlComm.Connection = sqlConn;
sqlComm.CommandType = CommandType.StoredProcedure;
sqlComm.CommandText = "GetCustomers";
SqlParameter sqlParam = new SqlParameter("@filter", SqlDbType.VarChar, 25);
if (companyName != null || companyName != "")
sqlParam.Value = companyName;
else
sqlParam.Value = "";
sqlParam.Direction = ParameterDirection.Input;
sqlComm.Parameters.Add(sqlParam);
sqlReader = sqlComm.ExecuteReader(CommandBehavior.CloseConnection);
}
ddl.DataSource = sqlReader;
ddl.DataTextField = "Company Name";
ddl.DataValueField = "Customer ID";
ddl.Items.Clear();
ddl.DataBind();
ddl.Items.Insert(0, new ListItem(String.Format("Select a Customer from [{0}]", ddl.Items.Count), "-1"));
}
示例15: ddlBillingAdrs_SelectedIndexChanged
protected void ddlBillingAdrs_SelectedIndexChanged(object sender, System.EventArgs e)
{
//For Billing Adrs DDL
DropDownList billingAddressDropDownList = new DropDownList();
billingAddressDropDownList = (DropDownList)dvCompany.FindControl("ddlBillingAdrs");
if (billingAddressDropDownList != null)
{
if (billingAddressDropDownList.SelectedValue == "1")
{
//Find existing Address Info
(dvCompany.FindControl("txtBillingAddress") as TextBox).Text = (dvCompany.FindControl("txtAddress") as TextBox).Text;
(dvCompany.FindControl("txtBillingCity") as TextBox).Text = (dvCompany.FindControl("txtCity") as TextBox).Text;
(dvCompany.FindControl("txtBillingState") as TextBox).Text = (dvCompany.FindControl("txtState") as TextBox).Text;
(dvCompany.FindControl("txtBillingZip") as TextBox).Text = (dvCompany.FindControl("txtZip") as TextBox).Text;
(dvCompany.FindControl("txtBillingCountry") as TextBox).Text = (dvCompany.FindControl("txtCountry") as TextBox).Text;
//Also make them readonly true
(dvCompany.FindControl("txtBillingAddress") as TextBox).Enabled = false;
(dvCompany.FindControl("txtBillingCity") as TextBox).Enabled = false;
(dvCompany.FindControl("txtBillingState") as TextBox).Enabled = false;
(dvCompany.FindControl("txtBillingZip") as TextBox).Enabled = false;
(dvCompany.FindControl("txtBillingCountry") as TextBox).Enabled = false;
}
else
{
//Also make them readonly false
(dvCompany.FindControl("txtBillingAddress") as TextBox).Enabled = true;
(dvCompany.FindControl("txtBillingCity") as TextBox).Enabled = true;
(dvCompany.FindControl("txtBillingState") as TextBox).Enabled = true;
(dvCompany.FindControl("txtBillingZip") as TextBox).Enabled = true;
(dvCompany.FindControl("txtBillingCountry") as TextBox).Enabled = true;
}
}
}