You must Sign In to post a response.

Display negative values in gridview

Hi all,

I have a gridview which dispalys the negative numbers in a column like ($2.00). It automatically applies brackets where it gets negative value.

How to restrict it and my coulumn should show negative like -$2.00.

Please help

thanks
Vineet


Comments

#639307    Author: sharad  28 Oct 2011 Member Level: Bronze   Points : 2

String.Format("{0:$#,##0.00;($#,##0.00);Zero}", value);

This will output "$1,240.00? if passed 1243.50. It will output the
same format but in parentheses if the number is negative, and will
output the string "Zero" if the number is zero.

#639309    Author: sharad  28 Oct 2011 Member Level: Bronze   Points : 3

Uae a TemplateField instead:

http://msdn.microsoft.com/en-us/library/bb288032.aspx[^]

Your code woould then be something like:


Collapse | Copy Code

<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='$<%#
Bind("Price") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.