本文整理汇总了C#中System.Web.UI.WebControls.ListItemCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ListItemCollection.Clear方法的具体用法?C# ListItemCollection.Clear怎么用?C# ListItemCollection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.ListItemCollection
的用法示例。
在下文中一共展示了ListItemCollection.Clear方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindListItem
public static void BindListItem(ListItemCollection LIC, DataView DataSource, string TextField, string ValueField)
{
LIC.Clear();
for (int i = 0; i < DataSource.Count; i++)
{
LIC.Add(new ListItem(DataSource[i][TextField].ToString(), DataSource[i][ValueField].ToString()));
}
}
示例2: FillTreeData
public static void FillTreeData(ListItemCollection lst, DataTable dtCommands, string fieldKey, string fieldName, string fieldParentID, string sortBy)
{
lst.Clear();
DataRow[] drRoots = dtCommands.Select(fieldParentID + " = " + 0, sortBy);
foreach (DataRow row in drRoots)
{
ListItem item = new ListItem();
item.Value = row[fieldKey].ToString();
item.Text = row[fieldName].ToString();
item.Attributes.Add("Level", "0");
lst.Add(item);
LoadCmdItem(lst, item, dtCommands, fieldKey, fieldName, fieldParentID, sortBy);
}
}
示例3: BindMetaTypesItemCollections
public static void BindMetaTypesItemCollections(ListItemCollection items, bool IsAllItems)
{
ResourceManager LocRM2 = new ResourceManager("Mediachase.Ibn.WebResources.App_GlobalResources.Admin.Resources.strDefault", Assembly.Load(new AssemblyName("Mediachase.Ibn.WebResources")));
ResourceManager LocRM = new ResourceManager("Mediachase.UI.Web.App_GlobalResources.Lists.Resources.strLists", typeof(CommonHelper).Assembly);
items.Clear();
if (IsAllItems)
items.Add(new ListItem(LocRM2.GetString("tAllTypes"), "-1"));
MetaTypeCollection coll = MetaType.GetMetaDataMetaTypes();
Hashtable htTypes = new Hashtable();
htTypes.Clear();
foreach (MetaType type in coll)
{
if (!(type.MetaDataType == MetaDataType.DictionaryMultivalue
|| type.MetaDataType == MetaDataType.DictionarySingleValue
|| type.MetaDataType == MetaDataType.EnumMultivalue
|| type.MetaDataType == MetaDataType.EnumSingleValue
|| type.MetaDataType == MetaDataType.StringDictionary
|| type.MetaDataType == MetaDataType.MetaObject))
htTypes.Add(type.Id.ToString(), type.FriendlyName);
}
items.Add(new ListItem(htTypes["31"].ToString(), "31"));
htTypes.Remove("31");
items.Add(new ListItem(htTypes["32"].ToString(), "32"));
htTypes.Remove("32");
items.Add(new ListItem(htTypes["26"].ToString(), "26"));
htTypes.Remove("26");
items.Add(new ListItem(MetaType.Load(MetaDataType.Money).FriendlyName, "9"));
items.Add(new ListItem(MetaType.Load(MetaDataType.Float).FriendlyName, "6"));
items.Add(new ListItem(htTypes["28"].ToString(), "28"));
htTypes.Remove("28");
items.Add(new ListItem(MetaType.Load(MetaDataType.DateTime).FriendlyName, "4"));
items.Add(new ListItem(LocRM.GetString("Dictionary"), "0"));
items.Add(new ListItem(htTypes["27"].ToString(), "27"));
htTypes.Remove("27");
items.Add(new ListItem(htTypes["30"].ToString(), "30"));
htTypes.Remove("30");
items.Add(new ListItem(htTypes["33"].ToString(), "33"));
htTypes.Remove("33");
items.Add(new ListItem(htTypes["29"].ToString(), "29"));
htTypes.Remove("29");
items.Add(new ListItem(htTypes["39"].ToString(), "39"));
htTypes.Remove("39");
items.Add(new ListItem(htTypes["40"].ToString(), "40"));
htTypes.Remove("40");
foreach (string s in htTypes.Keys)
items.Add(new ListItem(htTypes[s].ToString(), s));
}
示例4: InitListItems
/// <summary>
/// 绑定控件的ListItem项
/// </summary>
/// <param name="LIC"></param>
/// <param name="IsFistNull"></param>
public void InitListItems(ListItemCollection LIC, bool IsFistNull)
{
if (LIC.Count > 0)
{
LIC.Clear();
}
Hashtable ht = GetTextValue();
foreach (DictionaryEntry de in ht)
{
LIC.Add(new ListItem(de.Value.ToString(), de.Key.ToString()));
}
if (IsFistNull)
{
LIC.Insert(0, "");
}
}
示例5: DataBindTeacherTypeList
public void DataBindTeacherTypeList(ListItemCollection itemCollection, string teacherType)
{
itemCollection.Clear();
ListItem[] listItems = new ListItem[]
{
new ListItem("所有教师", "0"),
new ListItem("院内教师/助教", "1"),
new ListItem("院外教师", "2"),
new ListItem("院外助教", "3")
};
if(teacherType != null && teacherType.Trim().Length != 0)
foreach(ListItem listItem in listItems)
{
if(listItem.Value == teacherType.Trim())
{
listItem.Selected = true;
break;
}
}
itemCollection.AddRange(listItems);
}
示例6: Methods
public void Methods ()
{
ListItemCollection c;
ListItem i;
ListItem i2;
c = new ListItemCollection();
Assert.AreEqual (0, c.Count, "T1");
i = new ListItem("Item 1", "10");
c.Add(i);
Assert.AreEqual (1, c.Count, "T2");
i = new ListItem("This is item 2", "20");
c.Add(i);
Assert.AreEqual (2, c.Count, "T3");
Assert.AreEqual (null, c.FindByText(" is "), "T4");
Assert.AreEqual (i.Text, c.FindByText("This is item 2").Text, "T5");
Assert.AreSame (i, c.FindByText("This is item 2"), "T6");
Assert.AreEqual (1, c.IndexOf(c.FindByText("This is item 2")), "T7");
Assert.AreEqual (1, c.IndexOf(c.FindByValue("20")), "T8");
i = new ListItem("Item 3", "30");
Assert.IsFalse(c.Contains(i), "T9");
c.Add(i);
Assert.IsTrue(c.Contains(i), "T10");
i = new ListItem("Forth", "40");
i2 = new ListItem("Fifth", "50");
c.AddRange(new ListItem[] {i, i2});
Assert.AreEqual (5, c.Count, "T11");
c.RemoveAt(1);
Assert.AreEqual (4, c.Count, "T12");
Assert.AreEqual (null, c.FindByText("This is item 2"), "T13");
c.Clear();
Assert.AreEqual (0, c.Count, "T13");
}
示例7: DataBindSearchTermTagList
//绑定学期标识下拉列表
public void DataBindSearchTermTagList(ListItemCollection itemCollection, string termValue)
{
itemCollection.Clear();
DalOperationAboutCourses doac = new DalOperationAboutCourses();
DataTable dt = doac.FindAllTermTags().Tables[0];
string termTag = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
termTag = dt.Rows[i]["termTag"].ToString().Trim();
ListItem li = new ListItem(CommonUtility.ChangeTermToString(termTag), termTag);
if (termValue == li.Value)
{
li.Selected = true;
}
itemCollection.Add(li);
}
ListItem itemAll = new ListItem("全部学期", "all");
if ("all" == termValue) {
itemAll.Selected = true;
}
itemCollection.Add(itemAll);
}
示例8: LoadListItems
/// <summary>
/// Loads the list items.
/// </summary>
/// <param name="listCollection">The list.</param>
/// <param name="dataReader">The data reader.</param>
/// <param name="textField">The text field.</param>
/// <param name="valueField">The value field.</param>
/// <param name="selectedValue">The selected value.</param>
/// <param name="closeReader">if set to <c>true</c> [close reader].</param>
public static void LoadListItems(ListItemCollection listCollection, IDataReader dataReader, string textField, string valueField, string selectedValue, bool closeReader)
{
listCollection.Clear();
if (closeReader)
{
using (dataReader)
{
while (dataReader.Read())
{
string sText = dataReader[textField].ToString();
string sVal = dataReader[valueField].ToString();
ListItem l = new ListItem(sText, sVal);
if (!String.IsNullOrEmpty(selectedValue))
l.Selected = selectedValue.Matches(sVal);
listCollection.Add(l);
}
dataReader.Close();
}
}
else
{
while (dataReader.Read())
{
string sText = dataReader[textField].ToString();
string sVal = dataReader[valueField].ToString();
ListItem l = new ListItem(sText, sVal);
if (!String.IsNullOrEmpty(selectedValue))
l.Selected = selectedValue.Matches(sVal);
listCollection.Add(l);
}
}
}
示例9: BuscaUsuario
protected void BuscaUsuario()
{
try
{
IUsuarios negocio = new BusinessLogic();
USUARIO userSesion = Session["userToModify"] as USUARIO;
USUARIO usuario = negocio.BuscaUsuarioRol(userSesion.NOMBRECOMPLETO);
lblNombreUsuario.Text = userSesion.NOMBRECOMPLETO;
List<ROL> roles = Session["Roles"] as List<ROL>;
ListItemCollection collection = new ListItemCollection();
ListItem item = null;
if (usuario == null)
{
collection.Clear();
foreach (ListItem valor in rblPerfiles.Items)
{
item = new ListItem { Text=valor.Text,Value=valor.Value};
collection.Add(item);
}
rblPerfiles.Items.Clear();
foreach (ListItem valor in collection)
rblPerfiles.Items.Add(valor);
throw new Exception("Usuario no encontrado");
}
Session.Add("UsuarioBuscado", usuario);
collection.Clear();
usuario.ROLUSUARIO.ToList().OrderBy(rol => rol.IDROL).ToList().ForEach(rolSelected =>
{
roles.OrderBy(rol => rol.IDROL).ToList().ForEach(rol =>
{
if (rol.IDROL == rolSelected.IDROL)
{
item = new ListItem
{
Text = rol.DESCRIPCIONROL,
Value = rol.IDROL.ToString(),
Selected = true
};
}
else
{
item = new ListItem
{
Text = rol.DESCRIPCIONROL,
Value = rol.IDROL.ToString()
};
}
if(!collection.Contains(item))
collection.Add(item);
});
});
if (collection.Count > 0)
{
rblPerfiles.Items.Clear();
foreach (ListItem valor in collection)
rblPerfiles.Items.Add(valor);
}
}
catch (Exception ex)
{
MostrarError(ex.Message);
}
}
示例10: buildListBox
public void buildListBox(ListItemCollection Items,string[] values, string CustomInitialDisplayValue,string CustomInitialSubmitValue)
{
Items.Clear();
if(CustomInitialDisplayValue!=null) Items.Add(new ListItem(CustomInitialDisplayValue,CustomInitialSubmitValue));
for(int i=0;i<values.Length;i+=2)Items.Add(new ListItem(values[i+1],values[i]));
}
示例11: FillDatabaseVersions
public void FillDatabaseVersions(int packageId, ListItemCollection items, List<string> versions)
{
if (versions == null)
return;
// load package context
PackageContext cntx = PackagesHelper.GetCachedPackageContext(packageId);
items.Clear();
AddDatabaseVersion(cntx, ResourceGroups.MsSql2000, items, versions);
AddDatabaseVersion(cntx, ResourceGroups.MsSql2005, items, versions);
AddDatabaseVersion(cntx, ResourceGroups.MsSql2008, items, versions);
AddDatabaseVersion(cntx, ResourceGroups.MsSql2012, items, versions);
AddDatabaseVersion(cntx, ResourceGroups.MsSql2014, items, versions);
AddDatabaseVersion(cntx, ResourceGroups.MySql4, items, versions);
AddDatabaseVersion(cntx, ResourceGroups.MySql5, items, versions);
}
示例12: BuildOptions
protected void BuildOptions(ListItemCollection listItems, List<ChoiceOption> configuredOptions, List<string> values)
{
listItems.Clear();
bool hasValues = values != null && values.Count != 0;
List<string> valueList = hasValues ? new List<string>(values) : new List<string>();
var extraItem = new ListItem(ExtraOptionText, ExtraOptionValue, true);
foreach (ChoiceOption option in configuredOptions)
{
var newItem = new ListItem(option.Text, option.Value, option.Enabled);
if (hasValues)
{
newItem.Selected = valueList.Contains(option.Value);
valueList.Remove(option.Value);
}
else
{
newItem.Selected = option.Selected;
}
listItems.Add(newItem);
}
if (AllowExtraValue)
{
listItems.Add(extraItem);
}
if (hasValues && valueList.Count > 0)
{
extraItem.Selected = true;
SetExtraValue(valueList[0]);
}
}
示例13: LoadListItems
public static void LoadListItems(ListItemCollection list, IDataReader rdr, string textField, string valField, string selectedValue, bool closeReader)
{
list.Clear();
while (rdr.Read())
{
string sText = rdr[textField].ToString();
string sVal = rdr[valField].ToString();
ListItem l;
l = new ListItem(sText, sVal);
if (!String.IsNullOrEmpty(selectedValue))
{
if (IsMatch(selectedValue, sVal))
{
l.Selected = true;
}
}
list.Add(l);
}
if (closeReader)
rdr.Close();
}