• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

Formatting string for datagrid numeric column ....

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
Mamine
Asked:
Mamine
1 Solution
 
praneethaCommented:
in itemdatabound

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

0
 
praneethaCommented:
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
 
MamineAuthor Commented:
Is there a way of doing this in the dataformatstring eg something like dataformatstring="{0:N0}" ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
MamineAuthor Commented:
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
 
MamineAuthor Commented:
Duh I think I'm being dopey ... {0:N0} seems to do the job!
0
 
praneethaCommented:
really wow...
0
 
praneethaCommented:
it did not work for me...

0
 
s_sansanwalCommented:
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
 
MamineAuthor Commented:
Hmm, was doing that already but prefer to have the user interface constraints as close to the user interface level as poss.
0
 
MamineAuthor Commented:
... also it screw up the sorting as a string
0
 
MamineAuthor Commented:
oh yes, Praneetha you are right it doesn't work for me either - I was looking at NULL values
0
 
diablocuteCommented:
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
 
MamineAuthor Commented:
Brilliant - thx Diablo :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now