在这里 http://www.cnblogs.com/qqcrazyer/archive/2008/04/10/631455.html 看到了一个DropDownList无绑定数据的解决方案,感觉非常适合我。但是本人水平太底,不懂如何使用。
下面是代码,但不知道这代码如何使用,我使用的是VS2005,放到CS文件中后,出现错误:找不到类型或命名空间名称“WebSysDescription”(是否缺少 using 指令或程序集引用?)找不到类型或命名空间名称“WebCategory”(是否缺少 using 指令或程序集引用?)
还请各位多多指教,如何才能让我使用此方法。 1[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Themeable(false), WebSysDescription("ListControl_SelectedValue"), WebCategory("Behavior"), DefaultValue(""), Bindable(true, BindingDirection.TwoWay)]
2public virtual string SelectedValue
3{
4 get
5 {
6 int num1 = this.SelectedIndex;
7 if (num1 >= 0)
8 {
9 return this.Items[num1].Value;
10 }
11 return string.Empty;
12 }
13 set
14 {
15 if (this.Items.Count != 0)
16 {
17 if ((value == null) || (base.DesignMode && (value.Length == 0)))
18 {
19 this.ClearSelection();
20 return;
21 }
22 ListItem item1 = this.Items.FindByValue(value);
23 if ((((this.Page != null) && this.Page.IsPostBack) && this._stateLoaded) && (item1 == null))
24 {
25 throw new ArgumentOutOfRangeException("value", SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedValue" }));
26 }
27 if (item1 != null)
28 {
29 this.ClearSelection();
30 item1.Selected = true;
31 }
32 }
33 this.cachedSelectedValue = value;
34 }
35}
36
37
下面是代码,但不知道这代码如何使用,我使用的是VS2005,放到CS文件中后,出现错误:找不到类型或命名空间名称“WebSysDescription”(是否缺少 using 指令或程序集引用?)找不到类型或命名空间名称“WebCategory”(是否缺少 using 指令或程序集引用?)
还请各位多多指教,如何才能让我使用此方法。 1[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Themeable(false), WebSysDescription("ListControl_SelectedValue"), WebCategory("Behavior"), DefaultValue(""), Bindable(true, BindingDirection.TwoWay)]
2public virtual string SelectedValue
3{
4 get
5 {
6 int num1 = this.SelectedIndex;
7 if (num1 >= 0)
8 {
9 return this.Items[num1].Value;
10 }
11 return string.Empty;
12 }
13 set
14 {
15 if (this.Items.Count != 0)
16 {
17 if ((value == null) || (base.DesignMode && (value.Length == 0)))
18 {
19 this.ClearSelection();
20 return;
21 }
22 ListItem item1 = this.Items.FindByValue(value);
23 if ((((this.Page != null) && this.Page.IsPostBack) && this._stateLoaded) && (item1 == null))
24 {
25 throw new ArgumentOutOfRangeException("value", SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedValue" }));
26 }
27 if (item1 != null)
28 {
29 this.ClearSelection();
30 item1.Selected = true;
31 }
32 }
33 this.cachedSelectedValue = value;
34 }
35}
36
37
只需要在CS文件里写 DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue("qqcrazyer"));就行了?
但在aspx文件里怎么写?
WebCategory 改成 Category其实[]里的这些都可以去掉。