我在我的一个aspx页面中有以下代码:
<% foreach (Dependency dep in this.Common.GetDependencies(this.Request.QueryString["Name"]))
{ %>
<ctl:DependencyEditor DependencyKey='<%= dep.Key %>' runat="server" />
<% } %>
当我运行它时,我收到以下错误:
Parser Error Message: Cannot create an object of type 'System.Guid' from its string representation '<%= dep.Key %>' for the 'DependencyKey' property.
有没有办法在aspx页面中创建控件并传入Guid?我真的很讨厌必须循环并在后面的代码中创建这些控件只是因为......
注意:Dependency对象上的Key属性是 Guid。
答案 0 :(得分:1)
Dependency对象的关键属性可能是Guid,但是DependencyEditor的DependencyKey属性也是Guid吗?如果不是,否则在分配时不会调用正确的TypeConverter。
如果我没弄错的话,你也可以使用dep.Key.ToString()。
答案 1 :(得分:0)
是你的控件取值并假设它是一个GUID?您是否尝试使用该值实例化GUID?看起来这是一个演员问题
答案 2 :(得分:0)
它应该看起来像“&lt;%#dep.Key%&gt;”
祝你好运!答案 3 :(得分:0)
假设dep.Key是guid的字符串表示...而DependencyKey是Guid类型的属性
<ctl:DependencyEditor DependencyKey="<%= new Guid(dep.Key) %>" runat="server" />