Solved

Show the currency formats

Posted on 2009-07-05
21
1,362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
  • 2
  • +1
21 Comments
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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