Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...