Marin
Marin

Reputation: 69

How to use Eval function to validate an integer field & then show a text value?

I have this code :

<asp:TemplateField HeaderText="Active">
            <ItemTemplate>
                <%#Eval("IsActive")%>
            </ItemTemplate>
        </asp:TemplateField>

I have to use Eval to validate IsActive field, which is of type INTEGER. It can contain 1 or 0. By checking this value, I have to show to the user the output Yes or NO, because I don't want to show 1/0. Can you please tell me how to do it ?

Thanks in advance ;)

Upvotes: 1

Views: 2922

Answers (3)

Furqan Ashraf
Furqan Ashraf

Reputation: 40

if value is integer the lblsuccess will be shown. And if value is not integer then lblerror is shown. Place this code inside item template

<asp:Label id="lblsuccess" runat="server" Text="value is integer" 
Visible='<%# Int.TryParse("IntValue") ; %>' ></asp:Label>

<asp:Label id="lblerror" runat="server" Text="value is not integer" 
Visible='<%# !Int.TryParse("IntValue") ; %>' ></asp:Label>

Upvotes: -1

Terence
Terence

Reputation: 1374

<% #Eval("IsActive") == 1 ? "Yes" : "No" %>

Upvotes: 2

Tim Schmelter
Tim Schmelter

Reputation: 460208

Perhaps:

<%# (int)Eval("IsActive") == 1 ? "Yes" : "No" %>

Upvotes: 2

Related Questions