extension method in gridview eval
I have an extension method that I wrote but when I use it on an aspx page to render a label inside a gridview, it doesn't work.
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("TheStatus").ToMyStatus() %>'></asp:Label>
The extension method is a file called Appfunctions.cs:
public static class Extensions
{
public static string ToMyStatus(byte TheStatus)
{
//mycode
}
}
I've seen posts that say a namespace needs to be added with the Imports statement in the aspx page but the e开发者_开发百科xtention ToMyStatus is not in any particular namespace.
Any suggestions much appreciated.
Thanks.
You have missed this and type conversion.
public static class Extensions
{
public static string ToMyStatus(this byte TheStatus)
{
return "Hello : " + TheStatus;
}
}
Markup
<asp:Label ID="lblStatus"
runat="server"
Text='<%# ((byte)Eval("TheStatus")).ToMyStatus() %>'>
</asp:Label>
精彩评论