根据动态配置来提交对象属性值和设置属性值实现
//根据动态配置来提交对象属性值和设置属性值实现思路
foreach (Control c in this.Page.Form.Controls)
{
//检查是否继承接口的自定义控件
Type baseInterface = c.GetType().GetInterface("IBaseControls");
if (baseInterface != null)
{
//访问控件的配置属性
IBaseControls iConTrol = (IBaseControls)c;
PropertyInfo pBindField = c.GetType().GetProperty("BindField");
object BindFieldList = pBindField.GetValue(c, null);
if (!string.IsNullOrEmpty(BindFieldList.ToString()))
{
//根据配置属性给控件赋值
foreach (string BindField in BindFieldList.ToString().Split(','))
{
string propertyName = BindField.Split('=')[0];//控件属性
string propertyValue = BindField.Split('=')[1];//给属性赋值对应的表字段
PropertyInfo property = c.GetType().GetProperty(propertyName);
property.SetValue(c, propertyValue, null);
}
}
}
}
———————————————————————————————————
浩瀚的天空,会有改变的希望,世界会不会变得更加好,选择在於我们的手上。
浙公网安备 33010602011771号