inline coding Eval if statement

Total Post:117

Points:821
 1396  View(s)
Ratings:
Rate this:

How to make inline eval if control ?

<asp:TemplateField HeaderText="Name">               
<ItemTemplate>                   
<%# if(Eval("Bla Bla Bla").ToString().Length <=
15){Eval("Bla Bla Bla")}else{Eval("Bla Bla
Bla").ToString().Substring(0,15)}%>               
</ItemTemplate>           
</asp:TemplateField>
  1. Post:378

    Points:2694
    Re: inline coding Eval if statement

    Hi jay, 


    Use the tertiary expression '?':

    <asp:TemplateField HeaderText="Name">

                    <ItemTemplate>

                        <%# Eval("Bla Bla Bla").ToString().Length <= 15 ? Eval("Bla Bla Bla") : Eval("Bla Bla Bla").ToString().Substring(0,15) %>

                    </ItemTemplate>

                </asp:TemplateField>

Answer