Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态设置usercontrol属性_C#_Asp.net_.net 4.0 - Fatal编程技术网

C# 动态设置usercontrol属性

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关键字的解决方案,我能想到的最

我在asp.net中有一个需要动态设置属性的用户控件。属性和属性值在字典中,例如:

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;
}