Bijaya Khadka
Bijaya Khadka

Reputation: 159

condition in Eval while Binding data in gridview

This is my Code in Asp Gridview

<asp:TemplateField HeaderText="Commented By">
    <ItemTemplate>
         <h3 class="sfUserName">
<%#Eval("UserName")%></h3>

    </ItemTemplate>
</asp:TemplateField>

Here i have to check

if (<%#Eval("UserName")%>=="Annons")
{
   //Bind <%#Eval("Name")%>
}
else if (<%#Eval("UserName")%>!="Annons")
{
   //Bind <%#Eval("UserName")%>
}

How can i do this ?

Upvotes: 2

Views: 15008

Answers (1)

gzaxx
gzaxx

Reputation: 17590

This should work:

<h3 class="sfUserName">
    <%# Eval("UserName").ToString() == "Annons" ? Eval("Name") : Eval("UserName") %>
</h3>

Upvotes: 9

Related Questions