Solved

Formatting string for datagrid numeric column ....

Posted on 2004-10-06
14
422 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
Industry Leaders: 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!

 
LVL 15

Expert Comment

by:praneetha
ID: 12243187
0
 

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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…

730 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