本文整理汇总了C#中System.Web.UI.WebControls.DropDownList.ClearSelection方法的典型用法代码示例。如果您正苦于以下问题:C# DropDownList.ClearSelection方法的具体用法?C# DropDownList.ClearSelection怎么用?C# DropDownList.ClearSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.DropDownList
的用法示例。
在下文中一共展示了DropDownList.ClearSelection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectItem
public static void SelectItem(DropDownList control, string value)
{
control.ClearSelection();
ListItem item = control.Items.FindByValue(value);
if (item != null)
item.Selected = true;
}
示例2: SetSelectedItem
/// <summary>
/// 设置下拉框选中
/// </summary>
/// <param name="dropDownList">drop</param>
/// <param name="value">选中值</param>
public static void SetSelectedItem(DropDownList dropDownList, string value)
{
ListItem item = dropDownList.Items.FindByValue(value);
if (item != null)
{
dropDownList.ClearSelection();
item.Selected = true;
}
}
示例3: DropDownListSelect
public static void DropDownListSelect(ref DropDownList ddl, string value)
{
ddl.ClearSelection();
ListItem li = ddl.Items.FindByValue(value);
if (li != null)
{
li.Selected = true;
}
}
示例4: LoadParentDropDown
private void LoadParentDropDown(DropDownList ddl, Category self)
{
// Load up the Parent DropDown
ddl.ClearSelection();
ddl.Items.Add(new ListItem("none", "0"));
foreach (Category cat in Category.Categories)
{
if (self == null || !cat.Id.Equals(self.Id))
ddl.Items.Add(new ListItem(cat.CompleteTitle(), cat.Id.ToString()));
}
}
示例5: 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(DropDownList dropDownList, String selectedValue)
{
dropDownList.ClearSelection();
ListItem selectedListItem = dropDownList.Items.FindByValue(selectedValue);
if(selectedListItem != null)
{
selectedListItem.Selected = true;
return true;
}
else
{
return false;
}
}
示例6: RenderEditMode
/// <Summary>RenderEditMode renders the Edit mode of the control</Summary>
/// <Param name="writer">A HtmlTextWriter.</Param>
protected override void RenderEditMode( HtmlTextWriter writer )
{
PortalSettings _portalSettings = Globals.GetPortalSettings();
//For convenience create a DropDownList to use
DropDownList cboTimeZones = new DropDownList();
//Load the List with Time Zones
Localization.LoadTimeZoneDropDownList(cboTimeZones, ((PageBase)Page).PageCulture.Name, Convert.ToString(_portalSettings.TimeZoneOffset));
//Select the relevant item
if (cboTimeZones.Items.FindByValue(StringValue) != null)
{
cboTimeZones.ClearSelection();
cboTimeZones.Items.FindByValue(StringValue).Selected = true;
}
//Render the Select Tag
ControlStyle.AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.RenderBeginTag(HtmlTextWriterTag.Select);
for (int I = 0; I <= cboTimeZones.Items.Count - 1; I++)
{
string timeZoneValue = cboTimeZones.Items[I].Value;
string timeZoneName = cboTimeZones.Items[I].Text;
bool isSelected = cboTimeZones.Items[I].Selected;
//Add the Value Attribute
writer.AddAttribute(HtmlTextWriterAttribute.Value, timeZoneValue);
if (isSelected)
{
//Add the Selected Attribute
writer.AddAttribute(HtmlTextWriterAttribute.Selected, "selected");
}
//Render Option Tag
writer.RenderBeginTag(HtmlTextWriterTag.Option);
writer.Write(timeZoneName.PadRight(100).Substring(0, 50));
writer.RenderEndTag();
}
//Close Select Tag
writer.RenderEndTag();
}
示例7: SelectDropDownItem
/// <summary>
/// Selects the drop down item.
/// </summary>
/// <param name="dropdownListControl">The dropdown list control.</param>
/// <param name="value">The value.</param>
public static void SelectDropDownItem(DropDownList dropdownListControl, int value)
{
if (dropdownListControl == null)
{
throw new ArgumentNullException("Drop down control can not be null.");
}
dropdownListControl.ClearSelection();//clear existing selection.
//find the value in the drop down item.
ListItem item = dropdownListControl.Items.FindByValue(value.ToString());
if (item == null) //if item is null return to called method.
{
return;
}
item.Selected = true;
}
示例8: RenderEditMode
/// <Summary>RenderEditMode renders the Edit mode of the control</Summary>
/// <Param name="writer">A HtmlTextWriter.</Param>
protected override void RenderEditMode( HtmlTextWriter writer )
{
//For convenience create a DropDownList to use
DropDownList cboLocale = new DropDownList();
//Load the List with Locales
Localization.LoadCultureDropDownList(cboLocale, CultureDropDownTypes.NativeName, ((PageBase)Page).PageCulture.Name);
//Select the relevant item
if (cboLocale.Items.FindByValue(StringValue) != null)
{
cboLocale.ClearSelection();
cboLocale.Items.FindByValue(StringValue).Selected = true;
}
//Render the Select Tag
ControlStyle.AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.RenderBeginTag(HtmlTextWriterTag.Select);
for (int I = 0; I <= cboLocale.Items.Count - 1; I++)
{
string localeValue = cboLocale.Items[I].Value;
string localeName = cboLocale.Items[I].Text;
bool isSelected = cboLocale.Items[I].Selected;
//Add the Value Attribute
writer.AddAttribute(HtmlTextWriterAttribute.Value, localeValue);
if (isSelected)
{
//Add the Selected Attribute
writer.AddAttribute(HtmlTextWriterAttribute.Selected, "selected");
}
//Render Option Tag
writer.RenderBeginTag(HtmlTextWriterTag.Option);
writer.Write(localeName);
writer.RenderEndTag();
}
//Close Select Tag
writer.RenderEndTag();
}
示例9: BindEnum2DropDownList
/// <summary>
/// Pass in a DropDownList and typeof(YourEnum) as parameters to auto-bind a dropdownlist to an enum
/// </summary>
/// <param name="ddl">ddlMyDropDownList</param>
/// <param name="enumType">typeof(MyEnum)</param>
/// <param name="retainSelected">true/false indicating if the currently selected item should remain selected</param>
public static void BindEnum2DropDownList(DropDownList ddl, Type enumType, bool retainSelected)
{
// retain the currently selected item if possible
string currentlySelectedValue = string.Empty;
if (retainSelected)
currentlySelectedValue = ddl.SelectedValue;
ddl.DataSource = GetListItemsFromEnum(enumType);
ddl.DataTextField = "Text";
ddl.DataValueField = "Value";
ddl.DataBind();
// in the event that there was a selected item, keep it.
if (currentlySelectedValue != string.Empty && retainSelected == true)
{
ddl.ClearSelection();
ddl.Items.FindByText(currentlySelectedValue).Selected = true;
}
}
示例10: RenderViewMode
/// -----------------------------------------------------------------------------
/// <summary>
/// RenderViewMode renders the View (readonly) mode of the control
/// </summary>
/// <param name="writer">A HtmlTextWriter.</param>
/// <history>
/// [cnurse] 05/02/2006 created
/// </history>
/// -----------------------------------------------------------------------------
protected override void RenderViewMode(HtmlTextWriter writer)
{
PortalSettings _portalSettings = Globals.GetPortalSettings();
//For convenience create a DropDownList to use
var cboTimeZones = new DropDownList();
//Load the List with Time Zones
Localization.LoadTimeZoneDropDownList(cboTimeZones, ((PageBase) Page).PageCulture.Name, Convert.ToString(_portalSettings.TimeZoneOffset));
//Select the relevant item
if (cboTimeZones.Items.FindByValue(StringValue) != null)
{
cboTimeZones.ClearSelection();
cboTimeZones.Items.FindByValue(StringValue).Selected = true;
}
ControlStyle.AddAttributesToRender(writer);
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write(cboTimeZones.SelectedItem.Text);
writer.RenderEndTag();
}
示例11: BindDropDownList
/// <summary>
/// Binds the drop down list.
/// </summary>
/// <param name="dropDown">The drop down.</param>
/// <param name="value">The value.</param>
private void BindDropDownList(DropDownList dropDown, string value)
{
for (int intIndex = 0; intIndex < dropDown.Items.Count; intIndex++)
{
if (string.Equals(dropDown.Items[intIndex].Text, value))
{
dropDown.ClearSelection();
dropDown.Items[intIndex].Selected = true;
}
}
}
示例12: SetValue
public static void SetValue(string boField, bool boFieldIsNull, DropDownList dropDownList)
{
dropDownList.ClearSelection();
if (boFieldIsNull)
{
return;
}
else
{
ListItem li = dropDownList.Items.FindByValue(boField);
if (!(li == null))
{
li.Selected = true;
}
}
}
示例13: BindDropDownList
/// <summary>
/// Binds the drop down list.
/// </summary>
/// <param name="dropDown">The drop down.</param>
/// <param name="value">The value.</param>
private void BindDropDownList(DropDownList dropDown, string value)
{
if (dropDown != null)
{
if (dropDown.Items.FindByText(value) != null)
{
dropDown.ClearSelection();
dropDown.Items.FindByText(value).Selected = true;
}
}
}
示例14: SetSelectedValue
public static void SetSelectedValue(DropDownList ComboBox, string SelectedValue)
{
ListItem SelectedItem = ComboBox.Items.FindByValue(SelectedValue);
if (SelectedItem != null)
{
ComboBox.ClearSelection();
SelectedItem.Selected = true;
ComboBox.Enabled = false;
}
}
示例15: SetPrivacy
private void SetPrivacy(DropDownList ddl, string privacyLevel)
{
ddl.ClearSelection();
ListItem li = ddl.Items.FindByValue(privacyLevel);
if (!(li == null))
{
li.Selected = true;
}
}