?
Solved

Formatting string for datagrid numeric column ....

Posted on 2004-10-06
14
Medium Priority
?
437 Views
Last Modified: 2011-10-03
Can anyone tell me what syntax to use in an asp.net datagrid column so that a numeric value will show as blank if it is zero ?
0
Comment
Question by:Mamine
[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
14 Comments
 
LVL 15

Expert Comment

by:praneetha
ID: 12243010
in itemdatabound

if( e.Item.Cells[0].Text=="0")
e.Item.Cells[0].Text=" ";

0
 
LVL 15

Expert Comment

by:praneetha
ID: 12243018
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
{

if( e.Item.Cells[0].Text=="0")
e.Item.Cells[0].Text=" ";

}

// in item databound - assuming 1 column is the one you wat to manipulate
0
 

Author Comment

by:Mamine
ID: 12243049
Is there a way of doing this in the dataformatstring eg something like dataformatstring="{0:N0}" ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Mamine
ID: 12243328
Hmmm thats where I came from, but it does say those are only the common formats ... I wondered if there were some less common ones and what they might be
0
 

Author Comment

by:Mamine
ID: 12243481
Duh I think I'm being dopey ... {0:N0} seems to do the job!
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12243489
really wow...
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12243523
it did not work for me...

0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 12245231
Best solution is to get the number in string format from the sql.

Assume you have a column named "Price", then instead of

Select price from table1

do

Select
CASE CONVERT(VARCHAR(10), PRICE)
      WHEN '0' THEN ''
      ELSE CONVERT(VARCHAR(10), PRICE)
 END
AS Price
From Table1


Cheers,
S Sansanwal
0
 

Author Comment

by:Mamine
ID: 12246859
Hmm, was doing that already but prefer to have the user interface constraints as close to the user interface level as poss.
0
 

Author Comment

by:Mamine
ID: 12246913
... also it screw up the sorting as a string
0
 

Author Comment

by:Mamine
ID: 12247008
oh yes, Praneetha you are right it doesn't work for me either - I was looking at NULL values
0
 
LVL 2

Accepted Solution

by:
diablocute earned 2000 total points
ID: 12263272
Hi, there
Below code worked for me in VB.NET
Couple downers: 1) It didn't work in C#.NET
 2) You have to use TemplateColumn instead of BoundColumn

<asp:TemplateColumn>
  <ItemTemplate>
     <asp:Label ID="lblCol1"
        text='<%# iif ( DataBinder.Eval   (Container.DataItem, "COL1" ) <> 0,  
        DataBinder.Eval(Container.DataItem, "COL1", "{0:#,###.#0}"), "" ) %>'  
       Runat="server">
    </asp:Label>
  </ItemTemplate>                  
</asp:TemplateColumn>
0
 

Author Comment

by:Mamine
ID: 12274890
Brilliant - thx Diablo :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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