lorena Posted February 15, 2006 Posted February 15, 2006 I have a little function that just checks to see whether a database field is a date or null and I wanted to be able to make it accessible from all the forms on the site it is attached to - so I did this: Public Class ShortDateClass Public Function showShortDate(ByVal aDate As Object) If Not IsDBNull(aDate) Then Return aDate.ToShortDateString End If End Function End Class My question is this: how do I access this function from within a datagrid, for example? This is the code I used but it doesn't work: <asp:TemplateColumn HeaderText="Sched Complete Date"> <ItemTemplate> <asp:Label ID="lblSchedCompDate" Runat="server" text='<%#ShortDateClass.showShortDate(DataBinder.Eval(Container.DataItem,"sched_comp_date"))%>'/> </ItemTemplate> </asp:TemplateColumn> help? Quote
Mister E Posted February 16, 2006 Posted February 16, 2006 Trying making it a shared (static) function. You can then access it with ClassName.FunctionName without having to create an instance of the class first. Quote
lorena Posted February 16, 2006 Author Posted February 16, 2006 Where do I actually put the code? Do I create a separate Class Module or put it in the Global.asax file? Would this be the correct code? Public Class ShortDateClass Public Shared Function showShortDate(ByVal aDate As Object) If Not IsDBNull(aDate) Then Return aDate.ToShortDateString End If End Function End Class Quote
Mister E Posted February 17, 2006 Posted February 17, 2006 If it's in the same namespace it should not matter. If it's in a different namespace then you need to call it with MyNamespace.MyClass.MyFunction Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.