2 // System.Web.UI.WebControls.DropDownList.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 using System.Collections.Specialized;
\r
14 using System.ComponentModel;
\r
15 using System.Drawing;
\r
17 using System.Web.UI;
\r
19 namespace System.Web.UI.WebControls
\r
21 [ValidationProperty("SelectedItem")]
\r
22 public class DropDownList : ListControl, IPostBackDataHandler
\r
24 public DropDownList(): base()
\r
29 public override Color BorderColor
\r
33 return base.BorderColor;
\r
37 base.BorderColor = value;
\r
42 public override BorderStyle BorderStyle
\r
46 return base.BorderStyle;
\r
50 base.BorderStyle = value;
\r
55 public override Unit BorderWidth
\r
59 return base.BorderWidth;
\r
63 base.BorderWidth = value;
\r
67 [DefaultValue (0), WebCategory ("Misc")]
68 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
69 [WebSysDescription ("The index number of the currently selected ListItem.")]
\r
70 public override int SelectedIndex
\r
74 int index = base.SelectedIndex;
\r
75 if (index < 0 && Items.Count > 0) {
\r
77 Items [0].Selected = true;
\r
83 base.SelectedIndex = value;
\r
87 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
88 [Bindable (false), EditorBrowsable (EditorBrowsableState.Never)]
\r
89 public override string ToolTip
\r
91 // MS ignores the tooltip for this one
\r
93 return String.Empty;
\r
99 protected override void AddAttributesToRender(HtmlTextWriter writer)
\r
103 Page.VerifyRenderingInServerForm(this);
\r
105 writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
\r
106 base.AddAttributesToRender(writer);
\r
108 if(AutoPostBack && Page != null)
\r
110 writer.AddAttribute(HtmlTextWriterAttribute.Onchange, Page.GetPostBackClientEvent(this,""));
\r
111 writer.AddAttribute("language", "javascript");
\r
115 protected override ControlCollection CreateControlCollection()
\r
117 return new EmptyControlCollection(this);
\r
120 protected override void RenderContents(HtmlTextWriter writer)
\r
124 bool selected = false;
\r
125 foreach(ListItem current in Items)
\r
127 writer.WriteBeginTag("option");
\r
128 if(current.Selected)
\r
132 throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Multiselect_In_DropDownList"));
\r
135 writer.WriteAttribute("selected", "selected", false);
\r
137 writer.WriteAttribute("value", current.Value, true);
\r
139 HttpUtility.HtmlEncode(current.Text, writer);
\r
140 writer.WriteEndTag("option");
\r
141 writer.WriteLine();
\r
146 bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
\r
148 string[] vals = postCollection.GetValues(postDataKey);
\r
151 int index = Items.FindByValueInternal(vals[0]);
\r
152 if(index != SelectedIndex)
\r
154 SelectedIndex = index;
\r
161 void IPostBackDataHandler.RaisePostDataChangedEvent()
\r
163 OnSelectedIndexChanged(EventArgs.Empty);
\r