JeepGeekin
asked on
Conditional Eval
How do I add a conditional argument to a gridview? Basically, I need to check the value in a column to determine if another column will become a hyperlink or just display plain text. It seems like I should be able to alter this:
<asp:templatefield>
<itemtemplate>
<asp:HyperLink" runat="server" NavigateUrl="whatever">
<%#Eval("DisplayableTextCo lumn")%>
</asp:HyperLink>
</itemtemplate>
</asp:templatefield>
...To be something like this, but I'm not getting useful help from the error (other then it doesn't like what I have done with the eval):
<asp:templatefield>
<itemtemplate>
<% IF #Eval("ColumnToEvaluate") = 0 Then %>
<asp:HyperLink" runat="server" NavigateUrl="whatever">
<%#Eval("DisplayableTextCo lumn")%>
</asp:HyperLink>
<% ELSE %>
<%#Eval("DisplayableTextCo lumn")%>
<% END IF%>
</itemtemplate>
</asp:templatefield>
Also, is this a good way to do this? I'm not sure if it's efficient. Or would it be more efficient to handle this elsewhere (like in the code behind on the gridview databind event or something)?
<asp:templatefield>
<itemtemplate>
<asp:HyperLink" runat="server" NavigateUrl="whatever">
<%#Eval("DisplayableTextCo
</asp:HyperLink>
</itemtemplate>
</asp:templatefield>
...To be something like this, but I'm not getting useful help from the error (other then it doesn't like what I have done with the eval):
<asp:templatefield>
<itemtemplate>
<% IF #Eval("ColumnToEvaluate") = 0 Then %>
<asp:HyperLink" runat="server" NavigateUrl="whatever">
<%#Eval("DisplayableTextCo
</asp:HyperLink>
<% ELSE %>
<%#Eval("DisplayableTextCo
<% END IF%>
</itemtemplate>
</asp:templatefield>
Also, is this a good way to do this? I'm not sure if it's efficient. Or would it be more efficient to handle this elsewhere (like in the code behind on the gridview databind event or something)?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
lol. This is about the 10th issue you've helped me with Jason. Thanks! As always you provide simple, straight forward solutions while thinking outside the box.
Daniel, I'll see if I can get you some points. I didn't know that I could pull in the eval using DataBinder. You answered my question. I just don't like merging conditions into the ASP code if I can avoid it (though I didn't say that).
Daniel, I'll see if I can get you some points. I didn't know that I could pull in the eval using DataBinder. You answered my question. I just don't like merging conditions into the ASP code if I can avoid it (though I didn't say that).
JeepGeekin,
> Daniel, I'll see if I can get you some points. I didn't know that I
> could pull in the eval using DataBinder. You answered my question. I
> just don't like merging conditions into the ASP code if I can avoid it
> (though I didn't say that).
So do I, and I think it's a good practice to avoid inline code, but it's a personal opinion and others disagree :)
> Daniel, I'll see if I can get you some points. I didn't know that I
> could pull in the eval using DataBinder. You answered my question. I
> just don't like merging conditions into the ASP code if I can avoid it
> (though I didn't say that).
So do I, and I think it's a good practice to avoid inline code, but it's a personal opinion and others disagree :)
<%= IIF(DataBinder.Eval(Contai