“使用"ASP.NET标记中的等效名称空间 [英] "using" namespace equivalent in ASP.NET markup
问题描述
当我在ASP.NET 2.0中使用DataBound控件(例如Repeater)时,我知道检索绑定对象属性的最快方法(而不是将Eval()函数与Reflection一起使用)是强制转换将DataItem对象设置为它的类型,然后在本地使用该对象,如下所示:
When I'm working with DataBound controls in ASP.NET 2.0 such as a Repeater, I know the fastest way to retrieve a property of a bound object (instead of using Reflection with the Eval() function) is to cast the DataItem object to the type it is and then use that object natively, like the following:
<%#((MyType)Container.DataItem).PropertyOfMyType%>
问题是,如果此类型在名称空间中(99.99%的情况是这种情况),则使用此单条语句,因为由于ASP页没有类作用域的事实而导致时间更长,因此所有我的类型需要完全合格.
The problem is, if this type is in a namespace (which is the case 99.99% of the time) then this single statement because a lot longer due to the fact that the ASP page has no concept of class scope so all of my types need to be fully qualified.
<%#((RootNamespace.SubNamespace1.SubNamspace2.SubNamespace3.MyType)Container.DataItem).PropertyOfMyType%>
是否有任何一种 using
指令或可以在ASP.NET页面中放置的等效项,所以我不需要每次都使用完整的命名空间?
Is there any kind of using
directive or some equivalent I could place somewhere in an ASP.NET page so I don't need to use the full namespace every time?
推荐答案
我相信您可以添加以下内容:
I believe you can add something like:
<%@ Import Namespace="RootNamespace.SubNamespace1" %>
在页面顶部.
这篇关于“使用"ASP.NET标记中的等效名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!