Solved

Show the currency formats

Posted on 2009-07-05
21
1,339 Views
Last Modified: 2013-11-08
Hi Experts,
I want to display all the numbers in my web page,whether it being binded in Gridview or shown as a total of Gridview column in Indian currency format.Further I don't want indian rupee syntax there.

When I set the culture as
Thread.CurrentThread.CurrentCulture = new CultureInfo("hi-IN");

1389000 displayrs as 'Ru' 13,89,000.
But only where I am computing the number and displaying it as total.
I don't want to show Indian Style 'Ru' there and want only that format.
And I want to apply this format to gridview columns also.How to do this?
0
Comment
Question by:johny_bravo1
  • 9
  • 9
  • 2
  • +1
21 Comments
 
LVL 9

Expert Comment

by:Rahul Goel
ID: 24782931
Hey while converting the number to INR format, you need to replace the string with "Ru" with ""
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24782937

Thread.CurrentThread.CurrentCulture = new CultureInfo("hi-IN");
 e.Row.Cells[5].Text = total_compensation.ToString("c");

These are the lines where I am getting the results.
How can I replace the "Ru"
0
 
LVL 3

Expert Comment

by:DreamsTech
ID: 24782952
Simple Solution ,Use Ajax MaskedEditExtender and MaskedEditValidator.

In MaskedEditExtender ,set CurrencyFormat in Mask = "999,999,999,999.99" for INR ,similary u can set this value for diplaying currency format of any language.

Also,tie this extender to the Control diplaying the currency (Could be a ItemTemplate in a GridView)

eg :TargetControlID="txtPremium"

More details @ :http://www.asp.net/ajax/ajaxcontroltoolkit/samples/maskededit/maskededit.aspx



<cc1:MaskedEditExtender ID="meeLOBEstimatedPremium" runat="server" TargetControlID="txtPremium"

                                                                        Mask="999,999,999,999.99" OnFocusCssClass="MaskedEditFocus"

                                                                        OnInvalidCssClass="MaskedEditError" MaskType="Number" InputDirection="RightToLeft"

                                                                        AcceptNegative="None" DisplayMoney="None" />

Open in new window

0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24782963
I am using .Net 2.0
0
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
ID: 24783393

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("hi-IN");
Label1.Text = int.Parse("1389000").ToString("N2", info);
OR

CultureInfo info = new CultureInfo("hi-IN");
Label1.Text = int.Parse("1389000").ToString("N2",info);
0
 
LVL 15

Expert Comment

by:jinal
ID: 24783394
Sorry try this i made mistake in previous one.

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("hi-IN");
Label1.Text = int.Parse("1389000").ToString("N2");
or

CultureInfo info = new CultureInfo("hi-IN");
Label1.Text = int.Parse("1389000").ToString("N2",info);
 
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24783446
Thanks jinal,

Earlier my line was,
e.Row.Cells[5].Text = total_compensation.ToString("c");

e.Row.Cells[5].Text = decimal.Parse("1389000").ToString("N2");

I want to pass  total_compensation,which is calculated runtimw.Will u pls guide me?
0
 
LVL 15

Expert Comment

by:jinal
ID: 24783571
use this way
I hope total_compensation is int or double.
e.Row.Cells[5].Text = total_compensation.ToString("N2");

0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24783704
Thanks works perfectly.
Can I set the format to the Boundfield of the Gridview.How?
0
 
LVL 9

Expert Comment

by:Rahul Goel
ID: 24783758
total_compensation.ToString("c").Substring(2).Trim() here is your answer
0
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

 
LVL 8

Author Comment

by:johny_bravo1
ID: 24783848
Thanks Rahu_ketu_patal,that is solved.
I want to format the Boundfield in Gridview.
0
 
LVL 15

Expert Comment

by:jinal
ID: 24783931
For GridView : <<yourfield>>  = yourdatasource field name

<asp:BoundField DataField="<<yourfield>>" DataFormatString="{0:N0}" />
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24784245
:( Not working this time.
0
 
LVL 15

Expert Comment

by:jinal
ID: 24791424
Please put your aspx code snippet and datasource code snippet over here.
So i can suggest you more detail solution for this.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24791858
<asp:GridView ID="gvKhateAcquisition" AutoGenerateColumns="false" runat="server" CellPadding="4" ForeColor="#333333" OnRowDataBound="gvKhateAcquisition_RowDataBound" ShowFooter="True" Width="99%" OnSelectedIndexChanged="gvKhateAcquisition_SelectedIndexChanged" OnRowCreated="gvKhateAcquisition_RowCreated">
                                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                    <RowStyle BackColor="#EFF3FB" />
                                    <EditRowStyle BackColor="#2461BF" />
                                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                    <AlternatingRowStyle BackColor="White" />
                                    <Columns>
                                     <asp:BoundField DataField="Village_Name" HeaderText="Village" />
                                            <asp:BoundField DataField="khatedar_no" HeaderText="Khate No" />
                                            <asp:BoundField DataField="Khatedars" HeaderText="Khatedars" />
                                            <asp:BoundField DataField="new_survey_no" HeaderText="Survey No" />
                                            <asp:BoundField DataField="area_acquired" HeaderText="Area Acquired" />
                                            <asp:BoundField DataField="net_amount" HeaderText="Compensation" DataFormatString="{0:N0}"/>
                                            <asp:BoundField DataField="person" />
                                            <asp:BoundField DataField="Village_type" />
                                            </Columns>
                                </asp:GridView>

I am binding the Gridview in code behind.
0
 
LVL 15

Expert Comment

by:jinal
ID: 24792281
Hello ,
I think you are binding DataTable . Can you please check what is the datatype of net_amount column in Datatable.
dt.Columns["net_Amout"].DataType
Are you using RowDataBound to update net_amout column value.
 
 
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24793161
Hi,

I am binding  Dataset to the Gridview.

In RowDataBound I am calculating the running total to show in the footer,that's it.

 protected void gvKhateAcquisition_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
           
        if (e.Row.RowType == DataControlRowType.DataRow)
            {

                // add the treeTotal and treeValueTotal to the running total variables
                total_area_acq += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "area_acquired"));
                total_compensation += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "net_amount"));

            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[0].Text = "Total:";
                // for the Footer, display the running totals
                e.Row.Cells[4].Text = total_area_acq.ToString();
               
                e.Row.Cells[5].Text = total_compensation.ToString("N2");
                e.Row.Font.Bold = true;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";
                e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvKhateAcquisition, "Select$" + e.Row.RowIndex);
            }
    }
0
 
LVL 15

Assisted Solution

by:jinal
jinal earned 500 total points
ID: 24800324
Try this sample.
Let me know format is working or not.

/* Code Behind */
 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Globalization;

using System.Data;
 

public partial class _Default : System.Web.UI.Page

{

    double total_area_acq = 0.0;

    decimal total_compensation = 0;

    CultureInfo info = new CultureInfo("hi-IN");

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        {

            DataTable dt = new DataTable();

            dt.Columns.Add("Village_Name", typeof(string));

            dt.Columns.Add("khatedar_no", typeof(string));

            dt.Columns.Add("Khatedars", typeof(string));

            dt.Columns.Add("new_survey_no", typeof(string));

            dt.Columns.Add("area_acquired", typeof(string));

            dt.Columns.Add("net_amount", typeof(string));

            dt.Columns.Add("person", typeof(string));

            dt.Columns.Add("Village_Type", typeof(string));
 

            DataRow dr = dt.NewRow();

            dr[0] = "1";

            dr[1] = "1";

            dr[2] = "1";

            dr[3] = "1";

            dr[4] = "100";

            dr[5] = "1000.00";

            dr[6] = "1";

            dr[7] = "1";

            dt.Rows.Add(dr);
 

            dr = dt.NewRow();

            dr[0] = "2";

            dr[1] = "2";

            dr[2] = "2";

            dr[3] = "2";

            dr[4] = "200";

            dr[5] = "2000.00";

            dr[6] = "2";

            dr[7] = "2";

            dt.Rows.Add(dr);
 

            dr = dt.NewRow();

            dr[0] = "3";

            dr[1] = "3";

            dr[2] = "3";

            dr[3] = "3";

            dr[4] = "300";

            dr[5] = "300000.00";

            dr[6] = "3";

            dr[7] = "3";

            dt.Rows.Add(dr);
 

            gvKhateAcquisition.DataSource = dt;

            gvKhateAcquisition.DataBind();

        }       

    }

    protected void gvKhateAcquisition_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {
 

            // add the treeTotal and treeValueTotal to the running total variables

            total_area_acq += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "area_acquired"));

            total_compensation += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "net_amount"));
 

        }

        else if (e.Row.RowType == DataControlRowType.Footer)

        {

            e.Row.Cells[0].Text = "Total:";

            // for the Footer, display the running totals

            e.Row.Cells[4].Text = total_area_acq.ToString();
 

            e.Row.Cells[5].Text = total_compensation.ToString("N2",info);

            e.Row.Font.Bold = true;

        }

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvKhateAcquisition, "Select$" + e.Row.RowIndex);

        }
 

    }

}
 

/* ASPX File */
 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

       <asp:GridView ID="gvKhateAcquisition" AutoGenerateColumns="false" runat="server" CellPadding="4" ForeColor="#333333" OnRowDataBound="gvKhateAcquisition_RowDataBound" ShowFooter="True" Width="99%"  >

                                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

                                    <RowStyle BackColor="#EFF3FB" />

                                    <EditRowStyle BackColor="#2461BF" />

                                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

                                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

                                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

                                    <AlternatingRowStyle BackColor="White" />

                                    <Columns>

                                     <asp:BoundField DataField="Village_Name" HeaderText="Village" />

                                            <asp:BoundField DataField="khatedar_no" HeaderText="Khate No" />

                                            <asp:BoundField DataField="Khatedars" HeaderText="Khatedars" />

                                            <asp:BoundField DataField="new_survey_no" HeaderText="Survey No" />

                                            <asp:BoundField DataField="area_acquired" HeaderText="Area Acquired" />

                                            <asp:BoundField DataField="net_amount" HeaderText="Compensation" DataFormatString="{0:N0}"/>

                                            <asp:BoundField DataField="person" />

                                            <asp:BoundField DataField="Village_type" />

                                            </Columns>

                                </asp:GridView>

    </div>

    </form>

</body>

</html>

Open in new window

0
 
LVL 15

Expert Comment

by:jinal
ID: 24800338
One more thing...
When you display data in gridview it is not formatiing each row ( net_amout column) . It still display as string 300000.00 in my sample.  This is b'coz i consider DataType of column is string. If you want to format that to than column datatype either decima l or double, than and than DAtaFormatString works.
 
0
 
LVL 15

Assisted Solution

by:jinal
jinal earned 500 total points
ID: 24800351
Use this if you want to format currency for each row in above sample.
protected void gvKhateAcquisition_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            decimal dtemp = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "net_amount"));

            // add the treeTotal and treeValueTotal to the running total variables

            e.Row.Cells[5].Text = dtemp.ToString("N2", info);

            total_area_acq += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "area_acquired"));

            total_compensation += dtemp;
 

        }

        else if (e.Row.RowType == DataControlRowType.Footer)

        {

            e.Row.Cells[0].Text = "Total:";

            // for the Footer, display the running totals

            e.Row.Cells[4].Text = total_area_acq.ToString();
 

            e.Row.Cells[5].Text = total_compensation.ToString("N2",info);

            e.Row.Font.Bold = true;

        }

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvKhateAcquisition, "Select$" + e.Row.RowIndex);

        }
 

    }

Open in new window

0
 
LVL 8

Author Closing Comment

by:johny_bravo1
ID: 31600035
Works Great.Thanks a lot
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.NET Error 7 42
ASP.Net Session State alternatives 3 28
How to open a link from vb.net app 3 9
Re-position the objects 7 50
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

22 Experts available now in Live!

Get 1:1 Help Now