Solved

Griview Template field fail due to empty string ASP.NET

Posted on 2013-01-11
3
504 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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