日期:2014-05-17 浏览次数:20882 次
ListItem item = dropdownList.Items.FindByValue("9");
item.Selected = true;
/// <summary>
/// 根据控件名和属性名赋值
/// </summary>
/// <param name="ClassInstance">控件所在实例</param>
/// <param name="ControlName">控件名</param>
/// <param name="Value">属性值</param>
/// <param name="IgnoreCase">属否不区分大小写,false区分,true区分</param>
/// <returns></returns>
public static Object SetValueControlProperty(Object ClassInstance, string ControlName, Object Value, bool IgnoreCase)
{
Object Result = null;
Type myType = ClassInstance.GetType();
FieldInfo myFieldInfo = myType.GetField(ControlName, BindingFlags.NonPublic | BindingFlags.Instance);
string ComponentTypeName = myFieldInfo.FieldType.Name;
if(myFieldInfo != null && ComponentTypeName=="DropDownList")
{
//DropDownList控件,怎么写哦?
}
else if (myFieldInfo != null)
{
//以下是Label、Textbox、HiddenField,已能实现。
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(myFieldInfo.FieldType);
string PropertyDescriptorName="";
if (ComponentTypeName == "Label") PropertyDescriptorName = "Text";