C# 动态设置usercontrol属性
我在asp.net中有一个需要动态设置属性的用户控件。属性和属性值在字典中,例如:C# 动态设置usercontrol属性,c#,asp.net,.net-4.0,C#,Asp.net,.net 4.0,我在asp.net中有一个需要动态设置属性的用户控件。属性和属性值在字典中,例如: Dictionary<string, string> propertyValues; Control c = Page.LoadControl("~/Control.ascx") 这显然不起作用,因为item.key是字符串而不是属性 谢谢 Raj.你试过c[item.key]吗???或者可能c.Properties[item.Key]?我不认为有一个使用dynamic关键字的解决方案,我能想到的最
Dictionary<string, string> propertyValues;
Control c = Page.LoadControl("~/Control.ascx")
这显然不起作用,因为item.key是字符串而不是属性
谢谢
Raj.你试过
c[item.key]
吗???或者可能c.Properties[item.Key]
?我不认为有一个使用dynamic关键字的解决方案,我能想到的最佳替代方案是使用扩展方法来控制,并在扩展方法中使用反射。
dynamic c = Page.LoadControl("~/control.ascx");
foreach(var itemin propertyValues)
{
c.item.key = item.value;
}