Re: if else in datagrid item template

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Allan,

You can rely on the fact that HyperLink is similar to a Label when NavigateUrl
is empty and use a conditional IF to handle the bool logic inside the
NavigateUrl property itself:

<asp:HyperLink runat="server" Target="_blank" Text='<%# Eval("Title") %>'
NavigateUrl='<%# ((DateTime) Eval("FromDate") > DateTime.Now) ?
"/CPI/V2/Apps/PositionPosting/opening.aspx?id=" + Eval("Id") : string.Empty
%>'
/>

--
Dave Sexton

"Allan Ebdrup" <ebdrup@xxxxxxxxxxxxxxx> wrote in message
news:us$qwuc$GHA.3928@xxxxxxxxxxxxxxxxxxxxxxx
I'm using dotNet 2.0 and VS 2005.
I have a datagrid that I'm binding to an object data source (ODS), the
objects in the ODS have an FromDate property and an Id property.
Now I want to display a hyperling if(FromDate>DateTime.Now) and a label if
not, how do I do this the best way?
I tried to do a if else in the item template, but that doesn't work:
------------------
<%#
if(((OFiR.Recruitment.Staffing.Reporting.PositionPostingReporting)Container.DataItem).FromDate
DateTime.Now) {%>

<asp:HyperLink Target="_blank"
NavigateUrl='<%#"/CPI/V2/Apps/PositionPosting/opening.aspx?id=" + Eval("Id")
%>' Text='<%# Eval("Title") %>' runat="server"></asp:HyperLink>

<%# } else {%>

<asp:Label runat="server" Text='<%# Bind("Title") %>'
id="Label1"></asp:Label>

<%# } %>
------------------
How do I accoplish what I'm trying to do the best way?

Kind Regards,
Allan Ebdrup





.



Relevant Pages

  • Re: if else in datagrid item template
    ... You can rely on the fact that HyperLink is similar to a Label when ... NavigateUrl is empty and use a conditional IF to handle the bool logic ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Hyperlink in JTable
    ... "Hi is it possible to convert the data in a JTable into hyperlink? ... hyperlink but how to go the url link when we click the data. ... You can add a MouseListener to a Label to make it change ... color of the label on MouseOver like a link, also change the cursor ...
    (comp.lang.java.gui)
  • Re: Changing the mouse pointer over a textbox
    ... OnClick event will fire. ... I need to have a different URL as hyperlink address for each record. ... label because the value of the label's HyperlinkAddress property is ...
    (microsoft.public.access.formscoding)
  • Re: Edit Hyperlink with Code rather than the EditHyperlink Dialog
    ... text stored in a hyperlink field is not just the URL. ... You could create a label control on the form, ... textbox, and in the textboxes afterupdate event, set the HyperlinkAddress ... Private sub cmd_FollowHyperlink_Click ...
    (microsoft.public.access.externaldata)
  • Re: simulate actual clicking in VBA Code
    ... To follow the hyperlink address in a label named Label1, ... I would like the code to execute whatever is in the 0n_click ...
    (microsoft.public.access.modulesdaovba)