0
<asp:TemplateField HeaderText="Customer Account Name">
     <ItemTemplate>
         <asp:Label ID="lblRecieverClientAccountName" runat="server" 
              Text='<%#Eval("RecieverClientAccountName").ToString()) ? 
               String.Empty : 'Invalid Account number'
               ,"RecieverClientAccountName" %>'></asp:Label>
     </ItemTemplate>
</asp:TemplateField>

I need to check string is empty and show a custom message .It gives me an error "The server tag is not well formed."

शेखर
  • 17,412
  • 13
  • 61
  • 117
rohitha
  • 53
  • 1
  • 1
  • 7

5 Answers5

0

The problem is .ToString(). You should check it before .ToString() function

Try as below

<asp:Label ID="lblRecieverClientAccountName" runat="server" 
          Text='<%#Eval("RecieverClientAccountName")) ? 
           String.Empty : 'Invalid Account number'
           ,"RecieverClientAccountName" %>'></asp:Label>

Or check it for null values.

<asp:Label ID="lblRecieverClientAccountName" runat="server" 
          Text='<%#Eval("RecieverClientAccountName"))==
          null : 'Invalid Account number'
           ,"RecieverClientAccountName" %>'></asp:Label>

I have not tested it so far.

Edit 1

Try this

<%#(String.IsNullOrEmpty(Eval("RecieverClientAccountName").ToString()) ?...

Similar Question on SO Using '<%# Eval("item") %>'; Handling Null Value and showing 0 against

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
0
<asp:TemplateField HeaderText="Customer Account Name">
 <ItemTemplate>
     <asp:Label ID="lblRecieverClientAccountName" runat="server" 
          Text='<%#Eval("RecieverClientAccountName") ? 
           String.Empty : 'Invalid Account number, ' +
           Eval("RecieverClientAccountName") %>'></asp:Label>
 </ItemTemplate>

Kushal Vora
  • 342
  • 2
  • 16
Kaushik Maheta
  • 1,741
  • 1
  • 18
  • 27
0

Try this..

<asp:Label ID="lblRecieverClientAccountName" runat="server" 
           Text='<%#Eval("RecieverClientAccountName")) ?
           "" : 'Invalid Account number'
           ,"RecieverClientAccountName" %>'></asp:Label>
Rajeesh Menoth
  • 1,704
  • 3
  • 17
  • 33
0

You had error: "The server tag is not well formed." because of:

'Invalid Account number'

you have to change it to:

"Invalid Account number"

You can use Eval function like this:

Eval("RecieverClientAccountName") == null ? "" : Eval("RecieverClientAccountName").ToString()

or

Eval("RecieverClientAccountName") == DBNull.Value ? "" : Eval("RecieverClientAccountName").ToString()
Linh Dao
  • 1,305
  • 1
  • 19
  • 31
-1

Check Eval values Null or Not Null

<%# string.IsNullOrEmpty(Eval("RecieverClientAccountName").ToString())?  "Null" : "Values" %>
Jangli Coder
  • 89
  • 1
  • 1
  • 10
  • Exception happens at .ToString() if Eval("ReceiverClientAccountName") is null. – Linh Dao Aug 27 '18 at 06:46
  • string.IsNullOrEmpty(Eval("RecieverClientAccountName").ToString()) here i am checking the values is null or not null and it is not posible to happen error – Jangli Coder Sep 19 '18 at 12:49