Solved

Formatting string for datagrid numeric column ....

Posted on 2004-10-06
14
418 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
Comment Utility
in itemdatabound

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

0
 
LVL 15

Expert Comment

by:praneetha
Comment Utility
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
Comment Utility
Is there a way of doing this in the dataformatstring eg something like dataformatstring="{0:N0}" ?
0
 
LVL 15

Expert Comment

by:praneetha
Comment Utility
0
 

Author Comment

by:Mamine
Comment Utility
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
Comment Utility
Duh I think I'm being dopey ... {0:N0} seems to do the job!
0
 
LVL 15

Expert Comment

by:praneetha
Comment Utility
really wow...
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

by:praneetha
Comment Utility
it did not work for me...

0
 
LVL 9

Expert Comment

by:s_sansanwal
Comment Utility
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
Comment Utility
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
Comment Utility
... also it screw up the sorting as a string
0
 

Author Comment

by:Mamine
Comment Utility
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
Comment Utility
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
Comment Utility
Brilliant - thx Diablo :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

14 Experts available now in Live!

Get 1:1 Help Now