System.Web.UI.WebControls.ListControl.ClearSelection C# (CSharp) Method

ClearSelection() public method

public ClearSelection ( ) : void
return void
		public virtual void ClearSelection ()
		{
			if (items == null)
				return;

			int count = Items.Count;
			for (int i = 0; i<count; i++)
				items [i].Selected = false;
		}

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        ///     选择项
        /// </summary>
        /// <param name="control">ListControl控件</param>
        /// <param name="selectedValue">选择项</param>
        public static void SelectedItems(this ListControl control, object selectedValue)
        {
            var selValue = string.Empty;

            if (selectedValue is Enum)
            {
                selValue = Convert.ToString((int)selectedValue);
            }
            else if (selectedValue is bool)
            {
                selValue = selectedValue.ToString().ToLower();
            }
            else
            {
                selValue = selectedValue == null ? string.Empty : selectedValue.ToString();
            }

            // 清除当前选择的项
            control.ClearSelection();

            if (control.Items.FindByValue(selValue) != null)
            {
                control.Items.FindByValue(selValue).Selected = true;
            }
            else if (control.Items.FindByText(selValue) != null)
            {
                control.Items.FindByText(selValue).Selected = true;
            }
        }
All Usage Examples Of System.Web.UI.WebControls.ListControl::ClearSelection