Solved

Griview Template field fail due to empty string ASP.NET

Posted on 2013-01-11
3
502 Views
Last Modified: 2013-01-11
Hello experts,

I have a template field in gridview, I'm formating the data to Phone#, if the data is null or empty my template field fails.
<asp:TemplateField>
<HeaderTemplate>
 Phone Number</HeaderTemplate>
<HeaderStyle HorizontalAlign="Center" Width="75px" />
 <ItemTemplate>
<asp:Label ID="lblPHNumber" runat="server" Text='<%# String.Format("{0:000-0000}",Convert.ToInt64(DataBinder.Eval(Container.DataItem, "PHN_NUMBER")))%>' /></ItemTemplate>
</asp:TemplateField>

Open in new window

How  can I fix this.

Thanks,
ASPDEV
0
Comment
Question by:ASPDEV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:Jared_S
ID: 38767821
Can you create a function that evaluates if PHN_NUMBER is null or empty and return nothing if true, and return the formatted string if false?

then just bind myFunction("PHN_NUMBER")
0
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 500 total points
ID: 38767951
Try this,
<asp:Label ID="lblPHNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PHN_NUMBER") !="" ? String.Format("{0:000-0000}",Convert.ToInt64(DataBinder.Eval(Container.DataItem, "PHN_NUMBER"))) : ""%>' />

Open in new window

0
 

Author Closing Comment

by:ASPDEV
ID: 38768108
Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question