Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Griview Template field fail due to empty string ASP.NET

Posted on 2013-01-11
3
Medium Priority
?
507 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 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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