📄 htmlselect.cs
字号:
using System;
using System.Globalization;
using System.Collections;
using System.Collections.Specialized;
using System.Web.UI.WebControls;
namespace System.Web.UI.HtmlControls
{
/// <summary>
/// Summary description for HtmlSelect.
/// </summary>
//.custom instance void System.Web.UI.ControlBuilderAttribute
//.custom instance void [System]System.ComponentModel.DefaultEventAttribute
//.custom instance void System.Web.UI.ValidationPropertyAttribute
public class HtmlSelect : HtmlContainerControl,System.Web.UI.IParserAccessor,System.Web.UI.IPostBackDataHandler
{
private static object EventServerChange;
private static char[] SPLIT_CHARS;
private int cachedSelectedIndex;
private object dataSource;
private System.Web.UI.WebControls.ListItemCollection items;
static HtmlSelect()
{
char[] local0;
HtmlSelect.EventServerChange = new Object();
local0 = new Char[1];
local0[0] = (char)44;
HtmlSelect.SPLIT_CHARS = local0;
}
public HtmlSelect() : base("select")
{
this.cachedSelectedIndex = -1;
}
protected virtual void AddParsedSubObject(object obj)
{
if (obj as ListItem != null)
{
this.Items.Add((ListItem) obj);
return;
}
throw new HttpException(System.Web.HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "HtmlSelect", obj.GetType().Name));
}
protected virtual void ClearSelection()
{
int local0;
local0 = 0;
while (local0 < this.Items.Count)
{
this.Items[local0].Selected = false;
local0++;
}
}
protected virtual ControlCollection CreateControlCollection()
{
return new EmptyControlCollection(this);
}
protected virtual void LoadViewState(object savedState)
{
Triplet local0;
object local1;
if (savedState != null)
{
local0 = (Triplet) savedState;
this.LoadViewState(local0.First);
this.Items.LoadViewState(local0.Second);
local1 = local0.Third;
if (local1 != null)
this.Select((int[]) local1);
}
}
protected virtual void OnDataBinding(EventArgs e)
{
IEnumerable local0;
bool local1;
string local2;
string local3;
ICollection local4;
object local5;
ListItem local6;
IEnumerator local7;
string local8;
IDisposable local9;
this.OnDataBinding(e);
local0 = System.Web.UI.DataSourceHelper.GetResolvedDataSource(this.DataSource, this.DataMember);
if (local0 != null)
{
local1 = false;
local2 = this.DataTextField;
local3 = this.DataValueField;
this.Items.Clear();
local4 = local0 as ICollection;
if (local4 != null)
// this.Items.Capacity = local4.Count;
if (local2.Length != 0 || local3.Length != 0)
local1 = true;
local7 = local0.GetEnumerator();
try
{
while (local7.MoveNext())
{
local5 = local7.Current;
local6 = new ListItem();
if (local1)
{
if (local2.Length > 0)
local6.Text = System.Web.UI.DataBinder.GetPropertyValue(local5, local2, null);
if (local3.Length <= 0)
{
// goto i0;
}
local6.Value = System.Web.UI.DataBinder.GetPropertyValue(local5, local3, null);
}
else
{
local6.Value = (local8 = local5.ToString());
local6.Text = local8;
}
i0: this.Items.Add(local6);
}
}
finally
{
local9 = local7 as IDisposable;
if (local9 == null)
{
// goto i-1;
}
local9.Dispose();
}
}
if (this.cachedSelectedIndex != -1)
{
this.SelectedIndex = this.cachedSelectedIndex;
this.cachedSelectedIndex = -1;
}
}
protected virtual void OnPreRender(EventArgs e)
{
if (this.Page != null && this.Size > 1)
if (!(this.Disabled))
this.Page.RegisterRequiresPostBack(this);
}
protected virtual void OnServerChange(EventArgs e)
{
EventHandler local0;
local0 = (EventHandler) this.Events[HtmlSelect.EventServerChange];
if (local0 != null)
local0.Invoke(this, e);
}
protected virtual void RenderAttributes(HtmlTextWriter writer)
{
writer.WriteAttribute("name", this.RenderedNameAttribute);
this.Attributes.Remove("name");
this.Attributes.Remove("DataValueField");
this.Attributes.Remove("DataTextField");
this.Attributes.Remove("DataMember");
this.RenderAttributes(writer);
}
protected virtual void RenderChildren(HtmlTextWriter writer)
{
bool local0;
bool local1;
ListItemCollection local2;
int local3;
int local4;
ListItem local5;
local0 = false;
local1 = (this.Multiple == false);
writer.WriteLine();
writer.Indent = writer.Indent + 1;
local2 = this.Items;
local3 = local2.Count;
if (local3 > 0)
{
local4 = 0;
while (local4 < local3)
{
local5 = local2[local4];
writer.WriteBeginTag("option");
if (local5.Selected)
{
if (local1)
{
if (local0)
throw new HttpException(System.Web.HttpRuntime.FormatResourceString("HtmlSelect_Cant_Multiselect_In_Single_Mode"));
local0 = true;
}
writer.WriteAttribute("selected", "selected");
}
writer.WriteAttribute("value", local5.Value, true);
local5.Attributes.Remove("text");
local5.Attributes.Remove("value");
local5.Attributes.Remove("selected");
local5.Attributes.Render(writer);
writer.Write('>');
System.Web.HttpUtility.HtmlEncode(local5.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
local4++;
}
}
writer.Indent = writer.Indent - 1;
}
protected virtual object SaveViewState()
{
object local0;
object local1;
object local2;
local0 = this.SaveViewState();
local1 = this.Items.SaveViewState();
local2 = null;
if (this.Events[HtmlSelect.EventServerChange] != null || this.Disabled || !(this.Visible))
local2 = this.SelectedIndices;
if (local2 != null || local1 != null || local0 != null)
return new Triplet(local0, local1, local2);
return null;
}
protected virtual void Select(int[] selectedIndices)
{
int local0;
int local1;
this.ClearSelection();
local0 = 0;
while (local0 < (int) selectedIndices.Length)
{
local1 = selectedIndices[local0];
if (local1 >= 0 && local1 < this.Items.Count)
this.Items[local1].Selected = true;
local0++;
}
}
bool System.Web.UI.IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string[] local0;
bool local1;
int local2;
int local3;
int[] local4;
int[] local5;
int local6;
int local7;
local0 = postCollection.GetValues(postDataKey);
local1 = false;
if (local0 != null)
{
if (!(this.Multiple))
{
local2 = this.Items.FindByValueInternal(local0[0]);
if (this.SelectedIndex == local2)
goto i1;
this.SelectedIndex = local2;
local1 = true;
goto i1;
}
local3 = (int) local0.Length;
local4 = this.SelectedIndices;
local5 = new Int32[checked((uint) local3)];
local6 = 0;
while (local6 < local3)
{
local5[local6] = this.Items.FindByValueInternal(local0[local6]);
local6++;
}
if ((int) local4.Length == local3)
{
local7 = 0;
while (local7 < local3)
{
if (local5[local7] != local4[local7])
{
local1 = true;
goto i2;
}
local7++;
}
}
else
local1 = true;
i2: if (!(local1))
goto i1;
this.Select(local5);
}
else if (this.SelectedIndex != -1)
{
this.SelectedIndex = -1;
local1 = true;
}
i1: return local1;
}
void System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
{
this.OnServerChange(System.EventArgs.Empty);
}
protected virtual void TrackViewState()
{
this.TrackViewState();
this.Items.TrackViewState();
}
public event EventHandler ServerChange
{
add
{
this.Events.AddHandler(HtmlSelect.EventServerChange, value);
}
remove
{
this.Events.RemoveHandler(HtmlSelect.EventServerChange, value);
}
}
public virtual string DataMember
{
get
{
object local0;
local0 = this.ViewState["DataMember"];
if (local0 != null)
return (String) local0;
return System.String.Empty;
}
set
{
this.Attributes["DataMember"]= System.Web.UI.HtmlControls.HtmlControl.MapStringAttributeToString(value);
}
}
public virtual object DataSource
{
get
{
return this.dataSource;
}
set
{
if (value != null && value as System.ComponentModel.IListSource == null)
if (value as IEnumerable == null)
goto i3;
this.dataSource = value;
return;
i3: throw new ArgumentException(System.Web.HttpRuntime.FormatResourceString("Invalid_DataSource_Type", this.ID));
}
}
public virtual string DataTextField
{
get
{
string local0;
local0 = this.Attributes["DataTextField"];
if (local0 != null)
return local0;
return System.String.Empty;
}
set
{
this.Attributes["DataTextField"]= System.Web.UI.HtmlControls.HtmlControl.MapStringAttributeToString(value);
}
}
public virtual string DataValueField
{
get
{
string local0;
local0 = this.Attributes["DataValueField"];
if (local0 != null)
return local0;
return System.String.Empty;
}
set
{
this.Attributes["DataValueField"]= System.Web.UI.HtmlControls.HtmlControl.MapStringAttributeToString(value);
}
}
public virtual string InnerHtml
{
get
{
throw new NotSupportedException(System.Web.HttpRuntime.FormatResourceString("InnerHtml_not_supported", this.GetType().Name));
}
set
{
throw new NotSupportedException(System.Web.HttpRuntime.FormatResourceString("InnerHtml_not_supported", this.GetType().Name));
}
}
public virtual string InnerText
{
get
{
throw new NotSupportedException(System.Web.HttpRuntime.FormatResourceString("InnerText_not_supported", this.GetType().Name));
}
set
{
throw new NotSupportedException(System.Web.HttpRuntime.FormatResourceString("InnerText_not_supported", this.GetType().Name));
}
}
public System.Web.UI.WebControls.ListItemCollection Items
{
get
{
if (this.items == null)
{
this.items = new ListItemCollection();
if (this.IsTrackingViewState)
this.items.TrackViewState();
}
return this.items;
}
}
public bool Multiple
{
get
{
string local0;
local0 = this.Attributes["multiple"];
if (local0 == null)
return false;
return local0 == "multiple";
}
set
{
if (value)
{
this.Attributes["multiple"]= "multiple";
return;
}
this.Attributes["multiple"]= null;
}
}
public string Name
{
get
{
return this.UniqueID;
}
set
{
}
}
internal string RenderedNameAttribute
{
get
{
return this.Name;
}
}
public virtual int SelectedIndex
{
get
{
int local0;
local0 = 0;
while (local0 < this.Items.Count)
{
if (this.Items[local0].Selected)
return local0;
local0++;
}
if (this.Size <= 1 && !(this.Multiple))
{
if (this.Items.Count > 0)
this.Items[0].Selected = true;
return 0;
}
return -1;
}
set
{
if (this.Items.Count == 0)
{
this.cachedSelectedIndex = value;
return;
}
if (value < -1 || value >= this.Items.Count)
throw new ArgumentOutOfRangeException("value");
this.ClearSelection();
if (value >= 0)
this.Items[value].Selected = true;
}
}
protected virtual int[] SelectedIndices
{
get
{
int local0;
int[] local1;
int local2;
int[] local3;
int[] local4;
local0 = 0;
local1 = new Int32[3];
local2 = 0;
while (local2 < this.Items.Count)
{
if (this.Items[local2].Selected)
{
if (local0 == (int) local1.Length)
{
local3 = new Int32[checked((uint) local0 + local0)];
local1.CopyTo(local3, 0);
local1 = local3;
}
local0 = local0 + 1;
local1[local0] = local2;
}
local2++;
}
local4 = new Int32[checked((uint) local0)];
System.Array.Copy(local1, 0, local4, 0, local0);
return local4;
}
}
public int Size
{
get
{
string local0;
local0 = this.Attributes["size"];
if (local0 == null)
return -1;
return System.Int32.Parse(local0, CultureInfo.InvariantCulture);
}
set
{
this.Attributes["size"]= System.Web.UI.HtmlControls.HtmlControl.MapIntegerAttributeToString(value);
}
}
public string Value
{
get
{
int local0;
local0 = this.SelectedIndex;
if (local0 >= 0 && local0 < this.Items.Count)
return this.Items[local0].Value;
return System.String.Empty;
}
set
{
int local0;
local0 = this.Items.FindByValueInternal(value);
if (local0 >= 0)
this.SelectedIndex = local0;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -