How to use "If Condition" with <%#Eval("")%> Function

Wednesday, August 26, 2009


Sometimes you might need to use "if condition" in Eval function,

But if condition is not supported by Eval, So here is one of the way, you can
use if condition in Eval Function.

Paste this code in your HTML code,
Here ReplaceField() function will be called from code behind,

-----------IN HTMl code---------------
<td align="left">

You need to paste this below code in your code behind.

-----------IN code behind code--------
public string ReplaceField(string stat)
string newValue = "";
if (stat == "N/A")
newValue="<asp:Lable runat='server'>"+stat+"</asp:Lable>";
newValue = "<a href='" + stat + "'>" + stat + "</a>";

return newValue;

Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)

No comments :