[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Formatting string for datagrid numeric column ....

Posted on 2004-10-06
14
Medium Priority
?
448 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
Technology Partners: 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!

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
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

656 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