Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net(C#) inline coding Eval if statement

Tags:

c#

asp.net

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>
like image 932
Chicharito Avatar asked Apr 09 '10 11:04

Chicharito


People also ask

What is ASP.NET C?

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites. It allows you to use a full featured programming language such as C# or VB.NET to build web applications easily.

Is ASP.NET like C#?

ASP.NET is a web application development framework used to develop web applications using different back-end programming languages like C# where C# is used as an object-oriented programming language to develop web applications along with ASP.NET.

Can I use .NET with C?

. NET Framework is an object oriented programming framework meant to be used with languages that it provides bindings for. Since C is not an object oriented language it wouldn't make sense to use it with the framework.

Is C and .NET same?

C# is a programming language, . NET is a blanket term that tends to cover both the . NET Framework (an application framework library) and the Common Language Runtime which is the runtime in which . NET assemblies are run.


1 Answers

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>
like image 190
edosoft Avatar answered Sep 19 '22 16:09

edosoft