Solved

Griview Template field fail due to empty string ASP.NET

Posted on 2013-01-11
3
496 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
3 Comments
 
LVL 12

Expert Comment

by:Jared_S
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now