How to check if a value is empty?
Hi,
I want to show a list of my events. I want to show their Title, Start Date/End Date, Registration link and Registration Status (status can be Open, Coming Soon, Closed and Sold Out).
I am using a different AMS system to generate and manage my registrations, I just want to embed a link in my event pages in Sitefinity. In order to do so, I created a new 'Custom Field' for embedding my Registration Link and also created another 'Custom Field' for my event Status. Everything is working fine expect one thing. I want the Registration Status to be hyperlinked if the Status is 'Open', in other words: IF the 'Custom Field' for URL has a value, then hyperlink the value (link) to Status (Open) and if the custom field is empty and other statuses are selected, then only show the status (Coming Soon, Sold Out, Closed) with no hyperlink of course.
This is the code I am using in my Widget Template:
<
div
class
=
"Registration"
>
<
a
href
=
"<%# Eval("
OnlineRegistration")%>"><%# Eval("RegistrationStatus")%></
a
>
</
div
>
Ok, I'm winging this in the editor, so exuse any potential typos, but logic works...just toggle visibility based on String.IsNullOrEmpty
Change out your <a> to this
<
asp:HyperLink
runat
=
"server"
NavigateUrl='<%# Eval("OnlineRegistration")%>' Text='<%# Eval("RegistrationStatus")%>' Visible='<%# !String.IsNullOrEmpty(Eval("OnlineRegistration").ToString()) %>' />
<
asp:HyperLink
runat
=
"server"
NavigateUrl='<%# !String.IsNullOrEmpty(Eval("OnlineRegistration").ToString()) ? Eval("OnlineRegistration").ToString() : "#" %>' Text='<%# Eval("RegistrationStatus")%>' />
Steve,
Thanks. The first block of code just clears the status and it shows nothing. It just shows an empty box. I want to show the status but if the Status has no available hyperlink then unlink the status and just show text.
The second block, kinda works (although I prefer not to have a hyperlink for non-open statuses). It adds a '#' sign along with this text: SfCtrlPresentation to the URL. So, my URL changes to something like this: "localhost/.../ which returns a 404 when you click it.
Thanks