Solved

Formatting string for datagrid numeric column ....

Posted on 2004-10-06
14
419 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

23 Experts available now in Live!

Get 1:1 Help Now