We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Show the currency formats

Johny Bravo
Johny Bravo asked
on
Medium Priority
1,417 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?
Comment
Watch Question

Rahul Goel ITILSenior Consultant - Deloitte
CERTIFIED EXPERT

Commented:
Hey while converting the number to INR format, you need to replace the string with "Ru" with ""

Author

Commented:

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"
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

Author

Commented:
I am using .Net 2.0
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
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);
 

Author

Commented:
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?

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

Author

Commented:
Thanks works perfectly.
Can I set the format to the Boundfield of the Gridview.How?
Rahul Goel ITILSenior Consultant - Deloitte
CERTIFIED EXPERT

Commented:
total_compensation.ToString("c").Substring(2).Trim() here is your answer

Author

Commented:
Thanks Rahu_ketu_patal,that is solved.
I want to format the Boundfield in Gridview.

Commented:
For GridView : <<yourfield>>  = yourdatasource field name

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

Author

Commented:
:( Not working this time.

Commented:
Please put your aspx code snippet and datasource code snippet over here.
So i can suggest you more detail solution for this.

Author

Commented:
<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.

Commented:
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.
 
 

Author

Commented:
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);
            }
    }
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
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.
 
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Works Great.Thanks a lot
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.