Home > DeveloperSection > Forums > inline coding Eval if statement
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    August-27-2014 1:32 AM

 ASP.Net
Ratings:


 1 Reply(s)
 816  View(s)
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>



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-27-2014 2:53 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick