?? dropdownlist.cs
字號:
/*
*
導(dǎo)讀:
1、DropDownList是從ListControl中派生的,
其派生關(guān)系是 object --> Control --> WebControl --> ListControl --> ListBox
2、ListBox實(shí)現(xiàn)了,System.Web.UI.IPostBackDataHandler,
在其Items的Selected狀態(tài)改變時(shí),響應(yīng)SelectedIndexChanged事件
3、如果AutoPostBack屬性值為True,客戶端發(fā)生Onchange事件時(shí),進(jìn)行事件的回傳,
具體實(shí)現(xiàn)在AddAttributesToRender中
4、DropDownList只允許單選,ListBox才允許多選!
*
*/
using System;
namespace System.Web.UI.WebControls
{
/// <summary>
/// Summary description for DropDownList.
/// </summary>
public class DropDownList : ListControl,
System.Web.UI.IPostBackDataHandler
{
public DropDownList()
{
//
// TODO: Add constructor logic here
//
}
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
if (this.Page != null)
this.Page.VerifyRenderingInServerForm(this);
// writer.AddAttribute(20, this.UniqueID);
this.AddAttributesToRender(writer);
if (this.AutoPostBack && this.Page != null)
{
// writer.AddAttribute(22, this.Page.GetPostBackClientEvent(this, ""));
writer.AddAttribute("language", "javascript");
}
}
protected override ControlCollection CreateControlCollection()
{
return new EmptyControlCollection(this);
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
ListItemCollection local0;
int local1;
bool local2;
int local3;
ListItem local4;
local0 = this.Items;
local1 = this.Items.Count;
local2 = false;
if (local1 > 0)
{
local3 = 0;
while (local3 < local1)
{
local4 = local0[local3];
writer.WriteBeginTag("option");
if (local4.Selected)
{
if (local2)
throw new HttpException(System.Web.HttpRuntime.FormatResourceString("Cant_Multiselect_In_DropDownList"));
local2 = true;
writer.WriteAttribute("selected", "selected", false);
}
writer.WriteAttribute("value", local4.Value, true);
writer.Write('>');
System.Web.HttpUtility.HtmlEncode(local4.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
local3++;
}
}
}
bool System.Web.UI.IPostBackDataHandler.LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
string[] local0;
int local1;
local0 = postCollection.GetValues(postDataKey);
if (local0 != null)
{
local1 = this.Items.FindByValueInternal(local0[0]);
if (this.SelectedIndex != local1)
{
this.SelectedIndex = local1;
return true;
}
}
return false;
}
void System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
{
this.OnSelectedIndexChanged(System.EventArgs.Empty);
}
public override int SelectedIndex
{
get
{
int local0;
local0 = base.SelectedIndex;
if((local0 < 0)
&& (this.Items.Count > 0)
)
{
this.Items[0].Selected = true;
local0 = 0;
}
return local0;
}
set
{
base.SelectedIndex = value;
}
}
public override string ToolTip
{
get
{
return System.String.Empty;
}
set
{
}
}
public override System.Web.UI.WebControls.BorderStyle BorderStyle
{
get
{
return base.BorderStyle;
}
set
{
base.BorderStyle = value;
}
}
public override System.Web.UI.WebControls.Unit BorderWidth
{
get
{
return base.BorderWidth;
}
set
{
base.BorderWidth = value;
}
}
public override System.Drawing.Color BorderColor
{
get
{
return base.BorderColor;
}
set
{
base.BorderColor = value;
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -