本文整理汇总了C#中System.Web.UI.WebControls.ListBox.DataBind方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.DataBind方法的具体用法?C# ListBox.DataBind怎么用?C# ListBox.DataBind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.ListBox
的用法示例。
在下文中一共展示了ListBox.DataBind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatelstAccount
//所有权限
private void CreatelstAccount(ListBox listcontrol, int PermissionCategoryId)
{
Johnny.CMS.BLL.Access.Permission bll = new Johnny.CMS.BLL.Access.Permission();
listcontrol.DataSource = bll.GetList(PermissionCategoryId);
listcontrol.DataTextField = "PermissionName";
listcontrol.DataValueField = "PermissionId";
listcontrol.DataBind();
}
示例2: ListBindToData
public void ListBindToData(ListBox lb, DataTable dt, string dataTextField, string dataValueField)
{
lb.Items.Clear();
lb.DataSource = dt;
lb.DataTextField = dataTextField;
lb.DataValueField = dataValueField;
lb.DataBind();
}
示例3: CreateAllItems
//所有菜单栏目
private void CreateAllItems(ListBox listcontrolleft)
{
Johnny.CMS.BLL.SystemInfo.MenuCategory bll = new Johnny.CMS.BLL.SystemInfo.MenuCategory();
listcontrolleft.DataSource = bll.GetList();
listcontrolleft.DataTextField = "MenuCategoryName";
listcontrolleft.DataValueField = "MenuCategoryId";
listcontrolleft.DataBind();
}
示例4: ddlSongsFill
public static void ddlSongsFill(ListBox ddlSongs)
{
var response = SessionState.Client.GetAsync("api/song").Result;
if (response.IsSuccessStatusCode)
{
var songs = response.Content.ReadAsAsync<IEnumerable<Song>>().Result;
ddlSongs.DataTextField = "Title";
ddlSongs.DataValueField = "Id";
ddlSongs.DataSource = songs.ToList();
ddlSongs.DataBind();
}
}
示例5: GetListBox
public static ListBox GetListBox(string id, int rowCount, DataView dv, string dataValueField, string dataTextField, ListSelectionMode mode)
{
ListBox listBox = new ListBox();
listBox.ID = id;
listBox.Rows = rowCount;
listBox.SelectionMode = mode;
listBox.DataSource = dv;
listBox.DataValueField = dataValueField;
listBox.DataTextField = dataTextField;
listBox.DataBind();
return listBox;
}
示例6: FillDataToListBox
public static void FillDataToListBox(ListBox control, string table, string dataTextField, string dataValueField)
{
opendata();
string strCommand = "SELECT " + dataTextField + ", " + dataValueField + " FROM " + table;
sqladapter = new SqlDataAdapter(strCommand, sqlconn);
mydata = new DataSet();
sqladapter.Fill(mydata, strCommand);
control.DataSource = mydata;
control.DataTextField = dataTextField;
control.DataValueField = dataValueField;
control.DataBind();
closedata();
}
示例7: ddlArtistsFill
public static void ddlArtistsFill(ListBox ddlArtists, Action action)
{
var response = SessionState.Client.GetAsync("api/artist").Result;
if (response.IsSuccessStatusCode)
{
var artists = response.Content.ReadAsAsync<IEnumerable<Artist>>().Result.ToList();
ddlArtists.DataTextField = "Name";
ddlArtists.DataValueField = "Id";
ddlArtists.DataSource = artists.ToList();
ddlArtists.DataBind();
if (action != null)
{
action();
}
}
}
示例8: FillDataListBox
public static void FillDataListBox(DataSet dsFull, DataSet dsSelected, ListBox lb, string field, string val, string fieldSelect)
{
lb.DataSource = dsFull;
lb.DataTextField = field;
lb.DataValueField = val;
lb.DataBind();
if (dsSelected != null && dsSelected.Tables.Count > 0 && dsSelected.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsSelected.Tables[0].Rows.Count; i++)
{
foreach (ListItem item in lb.Items)
{
if (item.Value.Equals(dsSelected.Tables[0].Rows[i][fieldSelect].ToString()))
item.Selected = true;
}
}
}
}
示例9: BindRolesInListBox
private void BindRolesInListBox(ListBox lst)
{
try
{
DataTable dtRoles = GetAllRoles();
lst.DataSource = dtRoles;
lst.DataTextField = "RoleName";
lst.DataValueField = "RoleID";
lst.DataBind();
}
catch (Exception ex)
{
ProcessException(ex);
}
}
示例10: cargarComponentesPorEntregable
/// <summary>
/// Método que obtiene los entregables asociados al entregable seleccionado
/// </summary>
/// <param name="po_entregableComponente"></param>
private void cargarComponentesPorEntregable(cls_entregableComponente po_entregableComponente)
{
DataSet vo_dataSet = new DataSet();
try
{
//Si la lista de memoria se encuentra vacía, se realiza la consulta a nivel de base de datos
if (((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaMemoria.Count == 0)
{
vo_dataSet = cls_gestorEntregableComponente.selectEntregableComponente(((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto);
//Se recorren los registros obtenidos en la consulta
foreach (DataRow row in vo_dataSet.Tables[0].Rows)
{
cls_entregable vo_entregable = new cls_entregable();
cls_componente vo_componente = new cls_componente();
cls_entregableComponente vo_entregableComponente = new cls_entregableComponente();
vo_entregable.pPK_entregable = Convert.ToInt32(row["PK_entregable"]);
vo_componente.pPK_componente = Convert.ToInt32(row["PK_componente"]);
vo_componente.pNombre = Convert.ToString(row["nombre"]);
vo_entregableComponente.pEntregable = vo_entregable;
vo_entregableComponente.pComponente = vo_componente;
//Si el objeto no se encuentra en memoria, se agrega
if (((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaBaseDatos.Where(searchLinQ => searchLinQ.pPK_Componente == vo_entregableComponente.pPK_Componente).Count() == 0)
{
((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaBaseDatos.Add(vo_entregableComponente);
}
//Si el objeto no se encuentra en memoria, se agrega
if (((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pProyectoEntregableListaMemoria.Where(searchLinQ => searchLinQ.pPK_Entregable == vo_entregableComponente.pPK_Entregable).Count() > 0)
{
if (((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaMemoria.Where(searchLinQ => searchLinQ.pPK_Componente == vo_entregableComponente.pPK_Componente).Count() == 0)
{
((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pComponenteLista.Add(vo_componente);
((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaMemoria.Add(vo_entregableComponente);
}
}
}
}
//Si el objeto está asociado en memoria se utiliza
if (((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaMemoria.Where(searchLinQ => searchLinQ.pPK_Entregable == po_entregableComponente.pPK_Entregable).Count() > 0)
{
lbx_compasociados.DataSource = ((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaMemoria.Where(searchLinQ => searchLinQ.pPK_Entregable == po_entregableComponente.pPK_Entregable);
lbx_compasociados.DataTextField = "pNombreComponente";
lbx_compasociados.DataValueField = "pPK_Componente";
//Se realiza el Binding luego de saber de donde se tomarán los datos
lbx_compasociados.DataBind();
if (lbx_compasociados.Items.Count > 0)
{
//Si se leyeron datos asociados, se activa el botón de siguiente
btnNxt.Enabled = true;
}
}
//De lo contrario se consulta en base de datos para obtener, si existen, los registros asociados
else
{
vo_dataSet = cls_gestorEntregableComponente.selectEntregableComponente(po_entregableComponente);
lbx_compasociados.DataSource = vo_dataSet;
lbx_compasociados.DataTextField = "Nombre";
lbx_compasociados.DataValueField = "PK_Componente";
//Se realiza el Binding luego de saber de donde se tomarán los datos
lbx_compasociados.DataBind();
if (lbx_compasociados.Items.Count > 0)
{
ListBox lbx_pivot = new ListBox();
lbx_pivot.DataSource = vo_dataSet;
lbx_pivot.DataTextField = "Nombre";
lbx_pivot.DataValueField = "PK_Componente";
lbx_pivot.DataBind();
foreach (ListItem item in lbx_pivot.Items)
{
if (((CSLA.web.App_Variables.cls_variablesSistema)this.Session[CSLA.web.App_Constantes.cls_constantes.VARIABLES]).vs_proyecto.pEntregableComponenteListaMemoria.Where(searchLinQ => searchLinQ.pPK_Entregable == po_entregableComponente.pPK_Entregable &&
searchLinQ.pPK_Componente == Convert.ToInt32(item.Value)).Count() == 0)
{
lbx_compasociados.Items.Remove(item);
}
}
//Si se leyeron datos asociados, se activa el botón de siguiente
btnNxt.Enabled = true;
}
}
}
catch (Exception po_exception)
//.........这里部分代码省略.........
示例11: CreateDynamicControls
private void CreateDynamicControls()
{
productCat = db.ProductCategories.Where(x => x.Active == true).ToList();
string[] selectedItem = carItemsSelectedData.Value.Split(';');
List<CarItem> selectedCarItem = new List<CarItem>();
if (!string.IsNullOrEmpty(carItemsSelectedData.Value))
{
for (int i = 0; i < selectedItem.Count(); i++)
{
string[] tmp = selectedItem[i].Split('|');
selectedCarItem.Add(new CarItem() { ProductCatID = Convert.ToInt32(tmp[0].Trim()), ProductID = tmp[1].Trim() });
}
}
foreach (var item in productCat)
{
Panel p = new Panel();
p.CssClass = "form-group";
p.ID = "p_" + item.ProductCatID;
p.EnableViewState = true;
Label l = new Label();
l.Text = item.ProductCatName.ToUpper();
ListBox lb = new ListBox();
lb.ID = "ddlCat" + item.ProductCatID;
lb.SelectionMode = ListSelectionMode.Multiple;
lb.EnableViewState = true;
lb.CssClass = "form-control selectList";
lb.DataSource = db.Products.Where(x => x.Avtive == true && x.ProductCatID == item.ProductCatID).ToList();
lb.DataTextField = "ProductName";
lb.DataValueField = "ProductID";
p.Controls.Add(l);
p.Controls.Add(new LiteralControl("<br />"));
p.Controls.Add(lb);
placehoder1.Controls.Add(p);
lb.DataBind();
if (!string.IsNullOrEmpty(carItemsSelectedData.Value))
{
foreach (var obj in selectedCarItem.Where(x => x.ProductCatID == item.ProductCatID))
{
foreach (ListItem opt in lb.Items)
{
if (opt.Value == obj.ProductID)
opt.Selected = true;
}
}
}
}
}
示例12: lstBox_BindRefresh
//-----------------------------------------------------------------------------------------------------------------------------------
public static int lstBox_BindRefresh(bool showSel, bool ehBind, string XMLitem, ListBox _lstBox)
{
//Cria a Lista, carrega e destaca os ativos = 1...
List<item> _lstData = setLista(showSel, XMLitem);
if (ehBind)
{
_lstBox.DataSource = _lstData;
_lstBox.DataValueField = "SEL";
_lstBox.DataTextField = "VALUE";
_lstBox.DataBind();
}
//
bool ehVAR = false;
string strVAR = "";
string chkVAR = "";
int contAtivos = 0;
for (int i = 0; i < _lstBox.Items.Count; i++)
{
for (int j = 0; j < _lstData.Count; j++)
{
strVAR = _lstData[j].VALUE;
ehVAR = _lstBox.Items[i].ToString().Contains(strVAR);
chkVAR = _lstData[j].CHK.ToString();
if ((ehVAR) && (chkVAR == "1"))
{
_lstBox.Items[i].Attributes.Add("style", "background-color: #90EE90");
contAtivos++;
}
}
}
//Retorna o numero de Ativos...
return contAtivos;
}
示例13: OnInit
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_Table = new Table();
_tableRow = new TableRow();
_tCellFirst = new TableCell {VerticalAlign = VerticalAlign.Top, Width = 260};
_tableRow.Cells.Add(_tCellFirst);
_tCellSecond = new TableCell {VerticalAlign = VerticalAlign.Middle};
_tableRow.Cells.Add(_tCellSecond);
_tCellThird = new TableCell {VerticalAlign = VerticalAlign.Top, Width = 260};
_tableRow.Cells.Add(_tCellThird);
_Table.Rows.Add(_tableRow);
var items = StoreHelper.GetAllCountries().Select(country => new ListItem(country.Name, country.Code)).OrderBy(x => x.Text).ToList();
var selectedItems = GetSelectedCountries().Select(country => new ListItem(country.Name, country.Code)).OrderBy(x => x.Text).ToList();
foreach (var selectedItem in selectedItems)
{
if (items.Contains(selectedItem))
{
items.Remove(selectedItem);
}
}
_lbAllItems = new ListBox {SelectionMode = ListSelectionMode.Multiple, Width = 250, Rows = 10};
foreach (var item in items)
{
_lbAllItems.Items.Add(new ListItem(item.Text, item.Value));
}
_lbAllItems.DataBind();
var allItemsText = library.GetDictionaryItem("AllItems");
if (string.IsNullOrEmpty(allItemsText))
{
allItemsText = "All items";
}
_lblAllItems = new Label {Text = allItemsText, AssociatedControlID = _lbAllItems.ID};
var addText = library.GetDictionaryItem("Add");
if (string.IsNullOrEmpty(addText))
{
addText = "Add";
}
var removeText = library.GetDictionaryItem("Remove");
if (string.IsNullOrEmpty(removeText))
{
removeText = "Remove";
}
_tCellFirst.Controls.Add(_lblAllItems);
_tCellFirst.Controls.Add(_lbAllItems);
_btnMoveLeft = new Button {Text = removeText};
_btnMoveLeft.Click += BtnMoveLeftClick;
_btnMoveRight = new Button {Text = addText};
_btnMoveRight.Click += BtnMoveRightClick;
_tCellSecond.Controls.Add(_btnMoveLeft);
_tCellSecond.Controls.Add(_btnMoveRight);
_lbSelectedItems = new ListBox {SelectionMode = ListSelectionMode.Multiple, Width = 250, Rows = 10};
foreach (var selectedItem in selectedItems)
{
_lbSelectedItems.Items.Add(new ListItem(selectedItem.Text, selectedItem.Value));
}
_lbSelectedItems.DataBind();
var selectedItemsText = library.GetDictionaryItem("SelectedItems");
if (string.IsNullOrEmpty(selectedItemsText))
{
selectedItemsText = "Selected items";
}
_lblSelectedItems = new Label {Text = selectedItemsText, AssociatedControlID = _lbSelectedItems.ID};
_tCellThird.Controls.Add(_lblSelectedItems);
_tCellThird.Controls.Add(_lbSelectedItems);
if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_Table);
//if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_lblAllItems);
//if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_lbAllItems);
//if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_btnMoveLeft);
//if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_btnMoveRight);
//if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_lblSelectedItems);
//if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_lbSelectedItems);
}
示例14: FillListBox
/// <summary>
/// 数据集是List,绑定Name、Name
/// </summary>
/// <param name="lb">ListBox控件</param>
/// <param name="items">List数据集</param>
public static void FillListBox(ListBox lb, List<DropDownListItemObject> items)
{
List<DropDownListItemObject> newitems = new List<DropDownListItemObject>();
for (int i = 1; i <= items.Count; i++)
{
newitems.Insert(i, items[i - 1]);
}
lb.DataSource = items;
lb.DataTextField = "Name";
lb.DataValueField = "Code";
lb.DataBind();
}
示例15: fillListBox
protected void fillListBox(ListBox lst, DataSet ds, string textName, string valueName)
{
lst.DataSource = ds.Tables[0];
lst.DataTextField = textName;
lst.DataValueField = valueName;
lst.DataBind();
lst.Items.Insert(0, new ListItem("--Select--", "0"));
}