本文整理汇总了C#中System.Web.UI.WebControls.ListControl.ClearSelection方法的典型用法代码示例。如果您正苦于以下问题:C# ListControl.ClearSelection方法的具体用法?C# ListControl.ClearSelection怎么用?C# ListControl.ClearSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.ListControl
的用法示例。
在下文中一共展示了ListControl.ClearSelection方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SafeSelect
public static void SafeSelect(ListControl ddl, string val)
{
ListItem li = ddl.Items.FindByValue(val);
if (li != null)
{
ddl.ClearSelection();
li.Selected = true;
}
}
示例2: TrySelect
public static bool TrySelect(ListControl list, string text, string value, ref ListItem li)
{
li = null;
if (string.IsNullOrEmpty(value)) return false;
li = list.Items.FindByValue(value);
if (li != null)
{
list.ClearSelection();
li.Selected = true;
}
return (li != null);
}
示例3: SelectAdd
public static ListItem SelectAdd(ListControl list, string text, string value)
{
ListItem li = list.Items.FindByValue(value);
if (li == null)
{
li = new ListItem(text, value);
list.Items.Add(li);
}
list.ClearSelection();
li.Selected = true;
return li;
}
示例4: SetSelectedValue
/// <summary>
/// Selects the item in the list control that contains the specified value, if it exists.
/// </summary>
/// <param name="dropDownList"></param>
/// <param name="selectedValue">The value of the item in the list control to select</param>
/// <returns>Returns true if the value exists in the list control, false otherwise</returns>
public static bool SetSelectedValue(ListControl dropDownList, String selectedValue)
{
if (dropDownList != null)
{
dropDownList.ClearSelection();
ListItem selectedListItem = dropDownList.Items.FindByValue(selectedValue);
if (selectedListItem != null)
{
selectedListItem.Selected = true;
return true;
}
}
return false;
}
示例5: SelectedByValue
public static bool SelectedByValue(ListControl lst, string strValue)
{
ListItem item = lst.Items.FindByValue(strValue);
if (item == null)
{
return false;
}
if ((lst.GetType().ToString() != "System.Web.UI.WebControls.ListBox") && (lst.GetType().ToString() != "System.Web.UI.WebControls.CheckBoxList"))
{
lst.ClearSelection();
}
item.Selected = true;
return true;
}
示例6: SelectListItemByValue
public static void SelectListItemByValue(ListControl dropDownList, object value, object defaultValue)
{
if (dropDownList == null)
return;
dropDownList.ClearSelection();
var selectedItem = dropDownList.Items.FindByValue(value == null ? (defaultValue == null ? string.Empty : defaultValue.ToString()) : value.ToString());
if (selectedItem != null)
selectedItem.Selected = true;
}
示例7: SetFormItemListControl
/// <summary>列表框</summary>
/// <param name="entity"></param>
/// <param name="field"></param>
/// <param name="control"></param>
/// <param name="canSave"></param>
protected virtual void SetFormItemListControl(IEntity entity, FieldItem field, ListControl control, Boolean canSave)
{
if (control.Items.Count < 1 || !String.IsNullOrEmpty(control.DataSourceID))
{
control.DataBind();
// 这个赋值会影响RequiresDataBinding,而RequiresDataBinding会导致列表控件在OnPreRender阶段重新绑定,造成当前设定的值丢失。
//control.AppendDataBoundItems = false;
}
if (control.Items.Count < 1) return;
String value = String.Empty + entity[field.Name];
try
{
control.SelectedValue = value;
if (control.GetType() == typeof(DropDownList) || control.GetType() == typeof(ListControl))
{
/*
* 对于ListControl和DropDownList,仅PostBack时有可能抛出异常,初次打开有可能在PerformDataBinding中抛出异常,所以要做额外检测
*
* 因为DropDownList.SelectedIndex get时有可能修改Items[0].Selected, 所以下面代码最好避免访问SelectedIndex,SelectedValue
*
* 对于XControl.DropDownList始终没问题
* */
var selected = false;
for (int i = 0; i < control.Items.Count; i++)
{
var item = control.Items[i];
if (item.Selected)
{
selected = item.Value == value;
break;
}
}
if (!selected)
{
// 没有任何选中项或选中项不是设置的值
throw new ArgumentException();
}
}
}
catch (ArgumentException)
{
var li = control.Items.FindByValue(value);
if (li == null)
{
li = new ListItem(value, value);
control.Items.Add(li);
}
control.ClearSelection();
li.Selected = true;
}
}
示例8: TrySetValue
/// <summary>
/// Tenta selecionar o valor especificado no controle de lista.
/// </summary>
/// <param name="ctl">O <see cref="ListControl"/></param>
/// <param name="val">O valor.</param>
/// <param name="throwException">Se verdadeiro, uma exceção é lançada, ao invés de simplesmente returnar <c>false</c>.</param>
/// <returns>Verdadeiro se o valor pôde ser atribuído, falso caso contrário</returns>
/// <exception cref="IndexOutOfRangeException">Se o valor não for encontrado no <see cref="ListControl"/> especificado em <paramref name="ctl"/>.</exception>
public static bool TrySetValue(ListControl ctl, string val, bool throwException)
{
ListItem li = ctl.Items.FindByValue(val);
if (li == null)
{
if (throwException)
throw new IndexOutOfRangeException(String.Format("O valor '{0}' não foi encontrado no {1} '{2}'.", val, ctl.GetType().Name, ctl.ID));
else if (!IsSingleSelectionControl(ctl))
ctl.ClearSelection();
}
else
{
if (IsSingleSelectionControl(ctl))
ctl.SelectedValue = li.Value;
else
li.Selected = true;
}
return li != null;
}
示例9: SetSelectedByValue
/// <summary>
/// 设置ListControl选中项
/// </summary>
/// <param name="listControl">ListControl控件</param>
/// <param name="selectValue">选中的Value</param>
public static void SetSelectedByValue(ListControl listControl, string selectValue)
{
listControl.ClearSelection();
ListItem li = listControl.Items.FindByValue(selectValue);
if (li != null)
{
li.Selected = true;
}
}
示例10: SetMultSelectedByValue
/// <summary>
/// 设置ListControl选中项
/// </summary>
/// <param name="listControl">ListControl控件</param>
/// <param name="selectValue">选中的Value</param>
/// <param name="separator">分隔符</param>
public static void SetMultSelectedByValue(ListControl listControl, string selectValue, string separator)
{
listControl.ClearSelection();
string[] vals = selectValue.Split(new string[]{ separator}, StringSplitOptions.RemoveEmptyEntries);
foreach (ListItem li in listControl.Items)
{
li.Selected = vals.Contains(li.Value);
}
}
示例11: SetListControlSafely
/// <summary>
/// ��ȫ����<see cref="ListControl"/>��ֵ
/// </summary>
/// <param name="listCtrl">��Ҫ���õ� see cref="ListControl"/></param>
/// <param name="value">���õ�ֵ</param>
/// <param name="text">���õ�ֵ��</param>
/// <param name="addIfNotExists">����������Ƿ��������</param>
/// <param name="addEmptyItem">�Ƿ���ӿ���</param>
/// <param name="eventHandler">���ֵ��ѡ�У�����ô�ί��</param>
/// <param name="e">ί���¼�����</param>
/// <returns>�ҵ���<see cref="ListItem"/>�����û�ҵ����ؿ�����</returns>
public static ListItem SetListControlSafely(ListControl listCtrl, string value, string text, bool addIfNotExists, bool addEmptyItem, EventHandler eventHandler, EventArgs e)
{
if (listCtrl == null) {
return null;
}
ListItem li = null;
if (value != null) {
li = listCtrl.Items.FindByValue(value);
if (li == null && addIfNotExists) {
if (string.IsNullOrEmpty(text)) {
text = string.Format("({0})", value);
}
li = new ListItem(text, value);
}
}
if (addEmptyItem) {
listCtrl.Items.Insert(0, string.Empty);
}
if (li != null) {
listCtrl.ClearSelection();
li.Selected = true;
if (eventHandler != null) {
eventHandler(listCtrl, e);
}
}
return li;
}