INLINE CODING EVAL IF STATEMENT

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
 1129  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. Sumit Kesarwani

    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

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!