“using” namespace equivalent in ASP.NET markup

Question :

“using” namespace equivalent in ASP.NET markup,

Answer :

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%>  

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%>  

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" %>   

At the top of the page.

That’s the answer “using” namespace equivalent in ASP.NET markup, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you

Read More  grep a file, but show several surrounding lines?