/// <summary> /// 根据控件类型设定控件的值 /// </summary> /// <param name="_value">要设定的值。</param> public void SetValue(string _value) { //属性类型 if (o is MyProperty) { MyProperty mp = (MyProperty)o; System.Type type = mp.po.GetType(); System.Reflection.PropertyInfo pi = type.GetProperty(mp.propertyName); pi.SetValue(mp.po, _value, null); //return type.InvokeMember(mp.propertyName,System.Reflection.BindingFlags.GetProperty,null,mp.po,); //return mp.propertyName; } //字符串类型 if (o is String) { //this.SetString((string)o,_value); //return; string s = (string)o; s = _value; return; } //委托 if (o is Action) { Action action = (Action)o; action(_value); return; } //下拉框 if (o is DropDownList) { DropDownList ddl = (DropDownList)o; ListItem li = ddl.Items.FindByValue(_value); if (li != null) { ddl.ClearSelection(); li.Selected = true; } return; } //复选框 if (o is MyCheckBox) { MyCheckBox mcb = (MyCheckBox)o; if (mcb.Value == _value) { mcb.cb.Checked = true; } return; } //单选按钮 if (o is MyRadioButton) { MyRadioButton mrb = (MyRadioButton)o; if (mrb.Value == _value) { mrb.rb.Checked = true; } return; } //文本框 if (o is TextBox) { TextBox tb = (TextBox)o; tb.Text = _value; return; } //Label if (o is Label) { Label lbl = (Label)o; lbl.Text = _value; return; } //Literal if (o is Literal) { Literal ltl = (Literal)o; ltl.Text = _value; return; } }
/// <summary> /// 根据控件类型获得控件的值。 /// </summary> /// <returns>控件的值。</returns> public string GetValue() { //属性类型 if (o is MyProperty) { MyProperty mp = (MyProperty)o; System.Type type = mp.po.GetType(); System.Reflection.PropertyInfo pi = type.GetProperty(mp.propertyName); return((string)pi.GetValue(mp.po, null)); //return type.InvokeMember(mp.propertyName,System.Reflection.BindingFlags.GetProperty,null,mp.po,); //return mp.propertyName; } //字符串类型 if (o is String) { string s = (string)o; return(s); } //方法委托 if (o is Action) { Action action = (Action)o; return(action("_g_e_t_")); } //下拉框 if (o is DropDownList) { DropDownList ddl = (DropDownList)o; return(ddl.SelectedValue); } //复选框 if (o is MyCheckBox) { MyCheckBox mcb = (MyCheckBox)o; if (mcb.cb.Checked) { return(mcb.Value); } else { return("0"); } } //单选按钮 if (o is MyRadioButton) { MyRadioButton mrb = (MyRadioButton)o; if (mrb.rb.Checked) { return(mrb.Value); } } //文本框 if (o is TextBox) { TextBox tb = (TextBox)o; return(tb.Text); } //Label if (o is Label) { Label lbl = (Label)o; return(lbl.Text); } //Literal if (o is Literal) { Literal ltl = (Literal)o; return(ltl.Text); } return(string.Empty); }