formating to 2 decimal places in a GridView

sounds simple but I just cannot get anything to work

I have tried many variations of these

String.Format("{0:f2}",DataBinder.Eval(Container.DataItem, "A"))

DataBinder.Eval(Container.DataItem, "A", "{0:F2}")

 tried it in a bound column which does not work either but I want to use a textbox

any help please

 


jnc
0
jnc
9/18/2007 3:52:30 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

8 Replies
1109 Views

Similar Articles

[PageSpeed] 42

Hello,

 Take a look at the following article to see if this solves your problem :) Alot of formating information :)

http://msconline.maconstate.edu/tutorials/ASPNET2/ASPNET07/aspnet07-01.aspx 

 

Hope this helps. 


www.hopeasp.net
0
CSharpSean
9/18/2007 3:58:22 PM

Try "{0:0.00}"


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Charles
9/18/2007 4:06:22 PM

thanks I am on my way now

 

 


jnc
0
jnc
9/18/2007 4:07:46 PM

Thanks 

I did. it returned 0.00 I also tried #.## which returned #.##


jnc
0
jnc
9/18/2007 4:09:20 PM

How about without the quotation marks?  Sorry I'm in the middle of a build and can't do anything in VS.


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Charles
9/18/2007 4:16:45 PM

thanks but no, it won't build at all

 

 


jnc
0
jnc
9/18/2007 4:27:26 PM

well, I tried most and still get 2 or 1.9 where I want 2.00 and 1.90 they all looked like they were going to work but no there must be something else I am missing

<asp:TemplateField>
<
ItemTemplate>
<
asp:TextBox CssClass="ItemRow" ID="A" runat="server" Width="40px" Text='<%# DataBinder.Eval(Container.DataItem, "A", "{0:D2}") %>'></asp:TextBox>
</
ItemTemplate>
</
asp:TemplateField>

I have tried it without the css and still the same

 

 


jnc
0
jnc
9/18/2007 4:34:19 PM

 

using System;
class Sample
{
    enum Color { Yellow = 1, Blue, Green };
    static DateTime thisDate = DateTime.Now;

    public static void Main()
    {
        // Store the output of the String.Format method in a string.
        string s = "";

        Console.Clear();

        // Format a negative integer or floating-point number in various ways.
        Console.WriteLine("Standard Numeric Format Specifiers");
        s = String.Format(
            "(C) Currency: . . . . . . . . {0:C}\n" +
            "(D) Decimal:. . . . . . . . . {0:D}\n" +
            "(E) Scientific: . . . . . . . {1:E}\n" +
            "(F) Fixed point:. . . . . . . {1:F}\n" +
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(N) Number: . . . . . . . . . {0:N}\n" +
            "(P) Percent:. . . . . . . . . {1:P}\n" +
            "(R) Round-trip: . . . . . . . {1:R}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            -123, -123.45f);
        Console.WriteLine(s);

        // Format the current date in various ways.
        Console.WriteLine("Standard DateTime Format Specifiers");
        s = String.Format(
            "(d) Short date: . . . . . . . {0:d}\n" +
            "(D) Long date:. . . . . . . . {0:D}\n" +
            "(t) Short time: . . . . . . . {0:t}\n" +
            "(T) Long time:. . . . . . . . {0:T}\n" +
            "(f) Full date/short time: . . {0:f}\n" +
            "(F) Full date/long time:. . . {0:F}\n" +
            "(g) General date/short time:. {0:g}\n" +
            "(G) General date/long time: . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(M) Month:. . . . . . . . . . {0:M}\n" +
            "(R) RFC1123:. . . . . . . . . {0:R}\n" +
            "(s) Sortable: . . . . . . . . {0:s}\n" +
            "(u) Universal sortable: . . . {0:u} (invariant)\n" +
            "(U) Universal sortable: . . . {0:U}\n" +
            "(Y) Year: . . . . . . . . . . {0:Y}\n",
            thisDate);
        Console.WriteLine(s);

        // Format a Color enumeration value in various ways.
        Console.WriteLine("Standard Enumeration Format Specifiers");
        s = String.Format(
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
            "(D) Decimal number: . . . . . {0:D}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            Color.Green);
        Console.WriteLine(s);
Console.Readline();
    }
}
This class demos all the format types (got it off msdn so it must be right) and I checked it and it runs, so... 

TextBox1.Text = String.Format("{0:F}",1000);


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Charles
9/18/2007 4:57:25 PM
Reply:

Similar Artilces:

Formatting a decimal to 2 decimal places
Hi - just testing some code, and the code below returns a number with 3 decimal places (eg. 450.000). Will returning a decimal always give 3 decimal places, and if so, how can I remove the last one? I don't want to use: Return String.Format("{0:C}", decRunningTotal) - as that will automatically add a $ or £ or whatever to the start, and I'd like to control that. I'd really appreciate any help, thanks, Mark Function GetItemTotal() As String objDT = Session("Cart") Dim intCounter As Integer Dim decRunningTotal As Deci...

Master Details in two seperate GridView Controls
I am simply trying to have a list of people in the top grid control (works fine), then when selected have the second Grid Control show details for that person(not working). Here is what I am trying from the load event: Sub BindData() Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionSql")) Dim strPersonSQL, strActSQL As String strPersonSQL = "select row_id, first_name, last_name, middle_initial, dsi_id, created, created_by, program_of_study, email from tbl_person" Dim myPerCommand As New MySqlClient.MySqlComm...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Formatting output
Hi, I'm recovering data from an SQL table using C#. I have an object that is DR["budget"] I can place this into a text box using: budget.Text = DR["budget"].ToString(); but it displays as 5000.0000 even though the column in the table is declared as 'Money' (how many currencies use 4 dec places?) How can I get it to display as just 5000.00 ? I've tried a variety of suggestions from the web, but none seem to get anywhere close. Regards, Bernard D   try this: budget.Text =(DR["budget"].ToString("c");  S...

string format 2 decimal places
how do you do string format conversion to 2 decimal places?e.g. convert 100 to 100.00convert 110 to 110.00convert 100.000 to 100.00 etc....Thanks! Well, here's one way you could do it:double value = double.Parse("100");string result = value.ToString("f2");This is using Numeric Format Strings (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconNumericFormatStrings.asp). There's also a class called NumberFormatInfo which gives you slightly more abstract ways to modify the string formatting. Both of these should work in other cultures, as well, so 1,000.00 will...

Showing number to 2 decimal places in gridview
Hi, I am using a gridview control bound to an access database and one for the fields shows the price of an item. The prices in the database are stored in currency format. If an item is 35.00 it is displayed in the gridview as 35. It displays fine if the price was say 34.99. How can i ensure that the price is always displayed to 2 decimal places? I'm not sure if i have to alter my SQL query or whether it is a property of the gridview control. My simple SQL query is as follows:  SELECT tbl_products.prodCode, tbl_products.prodName, tbl_products.prodPrice FROM tbl_pro...

GridView control exporting to Excel in Net 2.0
Well, I did my homework and found 33,868 references to issues with the gridview control and Excel, none of which were close to whats happening with my app. I have a Gridview control on my VB.NET main page and when I right click on it the popup allows me to export to Excel just fine..5-6 columns, less than 100 rows..when I do the same on another page I get an Excel error popup : "This web query returned no data.."..both grids have a (Select) button in the 1st column. The one that works is simply that...the one that doesn't has the Button.Text defined as something e...

Limiting Column to 2 Decimal Places in Detailsview Control
 Hi people. Does anyone know how to limit the calculated value of a column in a detailsview control to two decimal places? Or perhaps there is a way to do it in the actual SQL code where it is being written. In DetailsView: <asp:BoundField DataField="ColNum2" HeaderText="ColNum2"  DataFormatString="{0:N2}" /> But in GridView, you need to add HtmlEncode="false" to the BoundField. <asp:BoundField DataField="ColNum2" HeaderText="ColNum2"  DataFormatString="{0:N2}" HtmlEncode="false" /&...

Stripping decimal points to only 2 places in Repeater Control?
As of now, I am calling up a "Cost" value in a repeater control like: <%# DataBinder.Eval(Container.DataItem, "Cost", "${0:#####.##}") %> That {0:#####.##} does not seem to work properly. As of now, when I just have "Cost" it pulls out 4 places after the decimal point where I only need 2. Can someone help me out with whats the right way to format the value? this is not an direct answer to your q but why dont you fix that problem with the db itself ? so you dont have to worry abt it displaying everytime...also it will save u a hell...

Need example of how to control number of decimal places shown in specific cell of gridview
Hi! I've been trying to figure out how to format the number of decimal places that show in a specific cell in a grid view.  I can't just format the column because the number of decimal places depends on the row and not the column.  I've tried the String.Format command but either the examples are wrong or it just plain doesn't work.  These are the variations I've tried so far: e.Row.Cells(iCnt).Text = String.Format("{0:0.0000}", e.Row.Cells(iCnt).Text) e.Row.Cells(iCnt).Text = String.Format("{0:d.dddd}", e.Row.Cells(iCnt).Text)...

Help! Find row on which a button was pressed in the gridview control in .NET 2.0
How do you get the exact row (and column data from that row)  on which a button was pressed within a gridview. In .NET v1 using the datagrid control the followingconstruction was available:objArgs.Item.Cells(n).Textusing the datagrid DataGridCommandEventArgs parameter. choices in gridview are     Sub cmdBackTestSummary(ByVal objSender As Object, ByVal objArgs As GridViewCommandEventArgs) ' objArgs.commandname ' objargs.commandarguement ' objargs.commandsource     End Sub but no objArgs.Item.Cells(n) So how do you get the exact row (and c...

Showing currency to 2 decimal places in gridview gets rounded off $ 57.50 as $ 58.00
Hi I am using a gridview . the ui web page gets the data from my SQL database table the problem is the data in table has value of $ 57.50 but when the data is displayed it gets rounded off  to $ 58.00 and similarly several other data gets rounded off. How can I avoid this and display the actual amount $ 57.50 instead of rounding off??   here is the code how they are displayed in UI and now displaying as $ 58.00 // Amount_Paid fetching data from dbo.V_Payment_Amount_List //DataFormatString="{0:c}" ConnectionFinanceDB.DisconnectToDatabase();Collectin...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Web resources about - formating to 2 decimal places in a GridView - asp.net.presentation-controls

Wikipedia:WikiProject Current Local City Time - Wikipedia, the free encyclopedia
This WikiProject is believed to be inactive. If you are not currently a member of the project, please consider joining it and/or its parent project ...

Wikipedia:WikiProject Current Local City Time - Wikipedia, the free encyclopedia
This WikiProject is believed to be inactive. If you are not currently a member of the project, please consider joining it and/or its parent project ...

Brooker website advert gallery
Our People Affiliations Contact Home Services About Us Positions Resume/CV formating Download an overview of our preferred resume/CV format and ...

Software - Future Shop Community Forums
Discuss software for all types of home or business applications.

AMERICAblog
skip to main skip to sidebar About us - Elections - Gay GOP Primary Schedule - Elections - Romney Economic Crisis - Jobs - TSA - Limbaugh - Fun ...

Wikiful - ARCTABLET NEWS
English (reference page) Translations to be done, your help is needed for the following languages: Korean Completed translations: French , ...

BoardGameGeek - BGG Bugs - Forum - BoardGameGeek
Register Board Games Home Recent Additions Welcome Wiki Subdomains All Abstract Games Customizable Games Children's Games Family Games Party ...

Special Character - Computer, Telephony and Electronics Glossary and Dictionary
Computer, Telephony and Electronics Glossary and Dictionary - CSGNetwork.Com's award winning online glossary of computer, telephony and electronics ...


FileBuzz - Find Software Fast
FileBuzz is your online download destination for Windows, Macintosh, Linux and PDA Freeware, Shareware and Demos.

Resources last updated: 12/27/2015 3:36:19 PM