Asp.Net(C#) inline coding Eval if statement
Hi all;
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>
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>
精彩评论