-
Notifications
You must be signed in to change notification settings - Fork 1
/
ComboBox.cs
125 lines (105 loc) · 2.93 KB
/
ComboBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Dojo.Net
{
public class ComboBox : DojoControl
{
protected int _selectedIndex = -1;
public ComboBox()
{
Items = new ListItemCollection();
}
public bool Required
{
get
{
return Attributes["required"] != null && bool.Parse(Attributes["required"]);
}
set
{
Attributes["required"] = value.ToString().ToLower();
}
}
protected override string DojoType
{
get
{
return "dijit.form.ComboBox";
}
}
public int SelectedIndex
{
get
{
return _selectedIndex;
}
set
{
if (_selectedIndex != -1)
Items[_selectedIndex].Selected = false;
if (value != -1)
Items[value].Selected = true;
_selectedIndex = value;
}
}
public ListItem SelectedItem
{
get
{
return _selectedIndex == -1 ? null : Items[SelectedIndex];
}
}
public string SelectedValue
{
get
{
return SelectedItem.Value;
}
set
{
SelectedIndex = Items.IndexOf(Items.FindByValue(value));
}
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public ListItemCollection Items
{
get;
set;
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Select;
}
}
public virtual string Name
{
get;
set;
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
if (String.IsNullOrEmpty(Name))
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
base.RenderBeginTag(writer);
}
protected override void RenderContents(HtmlTextWriter writer)
{
for (int i = 0; i < Items.Count; i++)
{
if (i == SelectedIndex)
writer.AddAttribute("selected", "selected");
writer.AddAttribute("value", Items[i].Value ?? Items[i].Text);
writer.RenderBeginTag(HtmlTextWriterTag.Option);
writer.Write(Items[i].Text ?? Items[i].Value);
writer.RenderEndTag();
}
base.RenderContents(writer);
}
}
}