格式十进制数印度货币格式 [英] Format Decimal number to Indian Currency Format

查看:245
本文介绍了格式十进制数印度货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#asp.net 4.0中我的项目,我需要显示的价格在印度curreny格式。


  

如。我的号码是12550000.00然后我想显示为1,25,50,000.00


但我想这个时候我将数据绑定到GridView要显示在GridView中,

,因此它可以在标记页来完成。在这里我们把评估和演示了绑定每个项目数据。

不过,我也想向大家解释我的塞纳里奥显示逗号sepearted值。

我有一组,其中用户对价值观的条目在GridView上面的文本框,然后点击添加。

这被添加在ViewState和ViewState是绑定到GridView控件。

在GridView的我也有它在ViewState中的值被传递回文本框在GridView控件的RowCommand事件点击编辑按钮。并在更新单击数据表视图状态更新和绑定回GridView的。

供您参考:

 保护无效gvPropertyConfig_RowCommand(对象发件人,GridViewCommandEventArgs E)
{
    尝试
    {
        如果(e.CommandName ==EditItem)
        {
            INT指数= Convert.ToInt32(e.CommandArgument);
            hdnIndex.Value = index.ToString();
            DataTable的DT =(数据表)的ViewState [proeprtyConfig];
            DataRow的博士= dt.Rows [指数]            如果(的Request.QueryString [CMD] ==编辑)
            {
                hdnPropertyConfigID.Value =博士[config_id]的ToString()。
                如果(DR [IS_ACTIVE]。的ToString()。ToLower将()==真)
                {
                    chkConfigVisible.Checked = TRUE;
                }
                其他
                {
                    chkConfigVisible.Checked = FALSE;
                }
                thIsActHed.Visible = TRUE;
                tdIsActchk.Visible = TRUE;
                tdbtnConfig.ColSpan = 2;
            }            txtScalableArea.Text =博士[scalable_area]的ToString()。
            txtCarpetArea.Text =博士[carpet_area]的ToString()。
            txtPricePerSqFt.Text =博士[price_per_sq_ft]的ToString()。
            txtCCPricePerSqFt.Text =博士[cc_price_per_sq_ft]的ToString()。
            txtTotalPrice.Text =博士[TOTAL_PRICE]的ToString()。
            ddlNoOfBedrooms.SelectedValue =博士[ROOM_ID]的ToString()。            btnUpdateConfig.Visible =真;
            btnConfigSubmit.Visible = FALSE;        }
        如果(e.CommandName ==DeleteItem)
        {
            INT指数= Convert.ToInt32(e.CommandArgument);
            DataTable的DT =(数据表)的ViewState [proeprtyConfig];
            DataRow的博士= dt.Rows [指数]
            如果(的Request.QueryString [CMD]。的ToString()==编辑)
            {
                INT PropertyConfigID = Convert.ToInt32(博士[0]的ToString());
                prConfigObj.deletePropertyConfig(PropertyConfigID);
                fillData();            }
            其他
            {
                dr.Delete();
                gvPropertyConfig.DataSource =(数据表)的ViewState [proeprtyConfig];
                gvPropertyConfig.DataBind();
            }
            clearConfigTextBoxes();
            btnConfigSubmit.Visible =真;
            btnUpdateConfig.Visible = FALSE;
        }
        setChecklistAttr();
    }
    赶上(异常前)
    {
        扔恩;
    }
}

下面是GridView中的标记,

 < ASP:的UpdatePanel ID =UpdatePanel1=服务器>
        <&的ContentTemplate GT;
            < D​​IV CLASS =tabBord>
                <表>
                    &所述; TR>
                        < TD合并单元格=4级=中间>
                            < H4>
                                物业配置信息与LT; / H4>
                        < / TD>
                    < / TR>
                    &所述; TR>
                        &所述; TD列跨度=4>
                            &所述p为H.;
                                注:只有LACS输入总价格。例如。如果1亿卢比比进入1,00,00,000
                            &所述; / P>
                            &所述p为H.;
                            &所述; / P>
                        < / TD>
                    < / TR>
                    &所述; TR>
                        &所述; TD>
                            < D​​IV ID =divconfigstr=服务器>
                                配置<跨度风格=颜色:红色> * LT; / SPAN>< / DIV>
                            <% - 类=displaynon - %GT;
                        < / TD>
                        &所述; TD>
                            < D​​IV ID =divnoofbedrooms=服务器>
                                < ASP:DropDownList的启用=假ID =ddlNoOfBedrooms=服务器>
                                < / ASP:DropDownList的>
                                &所述p为H.;
                                &所述; / P>
                            < / DIV>
                        < / TD>
                        &所述; TD>
                            可扩展的面积和LT;跨度风格=颜色:红色> * LT; / SPAN>
                        < / TD>
                        &所述; TD>
                            < ASP:文本框ID =txtScalableArea=服务器自动完成=关闭MAXLENGTH =10>< / ASP:文本框>< P>
                            &所述; / P>
                        < / TD>
                    < / TR>
                    &所述; TR>
                        &所述; TD>
                            地毯面积<跨度风格=颜色:红色> * LT; / SPAN>
                        < / TD>
                        &所述; TD>
                            < ASP:文本框ID =txtCarpetArea=服务器自动完成=关闭MAXLENGTH =10>< / ASP:文本框>< P>
                            &所述; / P>
                        < / TD>
                        &所述; TD>
                            价格/平方呎<跨度风格=颜色:红色> * LT; / SPAN>
                        < / TD>
                        &所述; TD>
                            < ASP:文本框ID =txtPricePerSqFt=服务器自动完成=关闭MAXLENGTH =10>< / ASP:文本框>< P>
                            &所述; / P>
                        < / TD>
                    < / TR>
                    &所述; TR>
                        &所述; TD>
                            CC价格/平方呎<跨度风格=颜色:红色> * LT; / SPAN>
                        < / TD>
                        &所述; TD>
                            < ASP:文本框ID =txtCCPricePerSqFt=服务器自动完成=关闭MAXLENGTH =10>< / ASP:文本框>< P>
                            &所述; / P>
                        < / TD>
                        &所述; TD>
                            总价(以LACS)LT;跨度风格=颜色:红色> * LT; / SPAN>
                        < / TD>
                        &所述; TD>
                            < ASP:文本框ID =txtTotalPrice=服务器自动完成=关闭MAXLENGTH =10>< / ASP:文本框>< P>
                            &所述; / P>
                        < / TD>
                    < / TR>
                    &所述; TR>
                        < TD ID =thIsActHed=服务器>
                            活性
                            < ASP:HiddenField ID =hdnPropertyConfigID=服务器/>
                            < ASP:HiddenField ID =hdnIndex=服务器/>
                        < / TD>
                        < TD ID =tdIsActchk=服务器>
                            < ASP:复选框ID =chkConfigVisible=服务器的CssClass =清单/>< P>
                            &所述; / P>
                        < / TD>
                        < TD ID =tdbtnConfig=服务器合并单元格=2>
                            < D​​IV CLASS =btnHold>
                                < ASP:按钮的ID =btnConfigSubmit=服务器文本=添加的OnClientClick =返回ValidatePropertyConfig();
                                    的CssClass =sendBtn的OnClick =btnConfigSubmit_Click/>
                                &安培; NBSP;
                                < ASP:按钮的ID =btnUpdateConfig=服务器的OnClick =btnUpdateConfig_Click的OnClientClick =返回ValidatePropertyConfig();
                                    的CssClass =sendBtn文本=更新可见=FALSE/>
                                < ASP:标签ID =lblerrconfig的CssClass =ERRORMSG=服务器>< / ASP:标签>
                            < / DIV>
                        < / TD>
                    < / TR>
                    &所述; TR>
                        &所述; TD列跨度=4>
                            < D​​IV CLASS =PHOLD>
                                < D​​IV CLASS =gridH>
                                    < ASP:GridView控件ID =gvPropertyConfig=服务器的AutoGenerateColumns =FALSEOnRowCommand =gvPropertyConfig_RowCommand
                                        OnRowDataBound =gvPropertyConfig_RowDataBound>
                                        <柱体和GT;
                                            < ASP:的TemplateField的HeaderText =没有房间ItemStyle-的CssClass =txtLT>
                                                <&ItemTemplate中GT;
                                                    < ASP:标签ID =lblno_of_bedrooms=服务器文本='<%#的eval(room_no)%>'>< / ASP:标签>
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                            < ASP:的TemplateField的HeaderText =可扩展面积ItemStyle-的CssClass =txtRT>
                                                <&EditItemTemplate的GT;
                                                    < ASP:文本框ID =txtscalable_area=服务器文本='<%#的eval(scalable_area)%>'>< / ASP:文本框>
                                                < / EditItemTemplate中>
                                                <&ItemTemplate中GT;
                                                    < ASP:标签ID =lblscalable_area=服务器文本='<%#的eval(scalable_area)%>'>< / ASP:标签>
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                            < ASP:的TemplateField的HeaderText =地毯面积ItemStyle-的CssClass =txtRT>
                                                <&EditItemTemplate的GT;
                                                    < ASP:文本框ID =txtcarpet_area=服务器文本='<%#的eval(carpet_area)%>'>< / ASP:文本框>
                                                < / EditItemTemplate中>
                                                <&ItemTemplate中GT;
                                                    < ASP:标签ID =lblcarpet_area=服务器文本='<%#的eval(carpet_area)%>'>< / ASP:标签>
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                            < ASP:的TemplateField的HeaderText =价格/平方英尺。 ItemStyle-的CssClass =txtRT>
                                                <&EditItemTemplate的GT;
                                                    < ASP:文本框ID =txtprice_per_sq_ft=服务器文本='<%#的eval(price_per_sq_ft)%>'>< / ASP:文本框>
                                                < / EditItemTemplate中>
                                                <&ItemTemplate中GT;
                                                    < ASP:标签ID =lblprice_per_sq_ft=服务器文本='<%#的eval(price_per_sq_ft)%>'>< / ASP:标签>
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                            < ASP:的TemplateField的HeaderText =CC价格/平方英尺。 ItemStyle-的CssClass =txtRT>
                                                <&EditItemTemplate的GT;
                                                    < ASP:文本框ID =txtcc_price_per_sq_ft=服务器文本='<%#的eval(cc_price_per_sq_ft)%>'>< / ASP:文本框>
                                                < / EditItemTemplate中>
                                                <&ItemTemplate中GT;
                                                    < ASP:标签ID =lblcc_price_per_sq_ft=服务器文本='<%#的eval(cc_price_per_sq_ft)%>'>< / ASP:标签>
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                            < ASP:的TemplateField的HeaderText =总价(以LACS)ItemStyle-的CssClass =txtRT>
                                                <&EditItemTemplate的GT;
                                                    < ASP:文本框ID =txttotal_price=服务器文本='<%#的eval(TOTAL_PRICE)%>'>< / ASP:文本框>
                                                < / EditItemTemplate中>
                                                <&ItemTemplate中GT;
                                                    < ASP:标签ID =lbltotal_price=服务器文本='<%#的eval(TOTAL_PRICE)%>'>< / ASP:标签>
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                            < ASP:的TemplateField的HeaderText =ItemStyle-的CssClass =txtLT>
                                                <&ItemTemplate中GT;
                                                    < ASP:ImageButton的=服务器ID =btnEditItem的CssClass =edBtn的ImageUrl =〜/管理/包括/图片/ edit.png
                                                        工具提示=编辑项目的CommandName =EditItemCommandArgument =<%#((GridViewRow)集装箱).RowIndex%GT; />
                                                    < ASP:ImageButton的=服务器ID =btnDeletetem的CssClass =edBtn的ImageUrl =〜/管理/包括/图片/ delete.png
                                                        的CommandName =DeleteItem工具提示=删除项目CommandArgument =<%#((GridViewRow)集装箱).RowIndex%GT; />
                                                < / ItemTemplate中>
                                            < / ASP:的TemplateField>
                                        < /专栏>
                                    < / ASP:GridView的>
                                < / DIV>
                            < / DIV>
                        < / TD>
                    < / TR>
                < /表>
            < / DIV>
        < /&的ContentTemplate GT;
    < / ASP:的UpdatePanel>


解决方案

使用的ToString函数的C参数,并确保您设置的globalaztion属性。

 字符串parseValueIntoCurrency(双号){
   //设置货币格式
   字符串curCulture = Thread.CurrentThread.CurrentCulture.ToString();
   System.Globalization.NumberFormatInfo currencyFormat =新
       System.Globalization.CultureInfo(curCulture).NumberFormat;   currencyFormat.CurrencyNegativePattern = 1;   返回number.ToString(C,currencyFormat);
}

如果你想使用一个不同的文化(比如你在美国是,你想印格式),那么就使用相应的CultureInfo元素,而不是得到它当前线程的。

EXTRA信息由于OP修改

好吧,你想要做的就是为网格这是什么,是创建一个受保护的功能它发生在数转换,并返回转换后的字符串(这基本上是高于code

现在,在ASPX的一面,你需要使用该功能在你的网格视图。结果
所以,与其这样:

 < ASP:的TemplateField的HeaderText =总价(以LACS)>
   <&EditItemTemplate的GT;
      < ASP:文本框ID =txttotal_price=服务器
                   文字='<%#的eval(TOTAL_PRICE)%>' />
    < / EditItemTemplate中>
    <&ItemTemplate中GT;
       < ASP:标签ID =lbltotal_price=服务器
                  文字='<%#的eval(TOTAL_PRICE)%>'> />
    < / ItemTemplate中>
 < / ASP:的TemplateField>

你会使用这个模板列:

 < ASP:的TemplateField的HeaderText =总价(以LACS)>
    <&EditItemTemplate的GT;
       < ASP:文本框ID =txttotal_price=服务器
                    文字='<%#的eval(TOTAL_PRICE)%>' />
    < / EditItemTemplate中>
    <&ItemTemplate中GT;
        <%#parseValueIntoCurrency(EVAL(TOTAL_PRICE))%GT;'>
     < / ItemTemplate中>
 < / ASP:的TemplateField>

请注意,两件事情。首先,我还是通过未格式化的值进入编辑模板,那我不是在实例项模板一个额外的标签。

我不这样做额外的标签究其原因,是因为我们只是不需要它在那里。这只是你只是不需要承担更位处理器/内存开销。

对于未格式化的值传递给文本字段,这是因为它最终会更容易验证,而不必解析出逗号和其他字符串元素。

I am using C# asp.net 4.0 in my project where i need to display price in India curreny format.

eg. my number is 12550000.00 then i want to display it as 1,25,50,000.00

But i want this to be displayed in gridview when i bind the data to the gridview,

so it can be done in markup page. where we place Eval for each Item Data Bound.

However, i would also like to explain my senario for displaying comma sepearted values.

i have a set of textboxes above the gridview where user makes entries of values and click add.

this gets add in the viewstate and the viewstate is binded to gridview.

In gridview i also have Edit button on click of it the values in viewstate is passed back to textbox on RowCommand Event of gridview. and on update click the viewstate datatable is updated and Binded back to gridview.

FOR your reference:

protected void gvPropertyConfig_RowCommand(object sender, GridViewCommandEventArgs e)
{
    try
    {
        if (e.CommandName == "EditItem")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            hdnIndex.Value = index.ToString();
            DataTable dt = (DataTable)ViewState["proeprtyConfig"];
            DataRow dr = dt.Rows[index];

            if (Request.QueryString["CMD"] == "Edit")
            {
                hdnPropertyConfigID.Value = dr["config_id"].ToString();
                if (dr["is_active"].ToString().ToLower() == "true")
                {
                    chkConfigVisible.Checked = true;
                }
                else
                {
                    chkConfigVisible.Checked = false;
                }
                thIsActHed.Visible = true;
                tdIsActchk.Visible = true;
                tdbtnConfig.ColSpan = 2;
            }

            txtScalableArea.Text = dr["scalable_area"].ToString();
            txtCarpetArea.Text = dr["carpet_area"].ToString();
            txtPricePerSqFt.Text = dr["price_per_sq_ft"].ToString();
            txtCCPricePerSqFt.Text = dr["cc_price_per_sq_ft"].ToString();
            txtTotalPrice.Text = dr["total_price"].ToString();
            ddlNoOfBedrooms.SelectedValue = dr["room_id"].ToString();

            btnUpdateConfig.Visible = true;
            btnConfigSubmit.Visible = false;

        }
        if (e.CommandName == "DeleteItem")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            DataTable dt = (DataTable)ViewState["proeprtyConfig"];
            DataRow dr = dt.Rows[index];
            if (Request.QueryString["CMD"].ToString() == "Edit")
            {
                int PropertyConfigID = Convert.ToInt32(dr[0].ToString());
                prConfigObj.deletePropertyConfig(PropertyConfigID);
                fillData();

            }
            else
            {
                dr.Delete();
                gvPropertyConfig.DataSource = (DataTable)ViewState["proeprtyConfig"];
                gvPropertyConfig.DataBind();
            }
            clearConfigTextBoxes();
            btnConfigSubmit.Visible = true;
            btnUpdateConfig.Visible = false;


        }
        setChecklistAttr();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

Below is the markup for Gridview,

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div class="tabBord">
                <table>
                    <tr>
                        <td colspan="4" class="middle">
                            <h4>
                                Property Config Information</h4>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <p>
                                Note: Enter total prices in lacs only. Eg. If 1 Crore than enter 1,00,00,000
                            </p>
                            <p>
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="divconfigstr" runat="server">
                                Configuration<span style="color: Red">*</span></div>
                            <%--class="displaynon"--%>
                        </td>
                        <td>
                            <div id="divnoofbedrooms" runat="server">
                                <asp:DropDownList Enabled="false" ID="ddlNoOfBedrooms" runat="server">
                                </asp:DropDownList>
                                <p>
                                </p>
                            </div>
                        </td>
                        <td>
                            Scalable Area <span style="color: Red">*</span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtScalableArea" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Carpet Area <span style="color: Red">*</span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtCarpetArea" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
                            </p>
                        </td>
                        <td>
                            Price/Sq.Ft.<span style="color: Red">*</span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtPricePerSqFt" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            CC Price/Sq.Ft.<span style="color: Red">*</span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtCCPricePerSqFt" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
                            </p>
                        </td>
                        <td>
                            Total Price (in lacs)<span style="color: Red">*</span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtTotalPrice" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td id="thIsActHed" runat="server">
                            Active
                            <asp:HiddenField ID="hdnPropertyConfigID" runat="server" />
                            <asp:HiddenField ID="hdnIndex" runat="server" />
                        </td>
                        <td id="tdIsActchk" runat="server">
                            <asp:CheckBox ID="chkConfigVisible" runat="server" CssClass="checklist" /><p>
                            </p>
                        </td>
                        <td id="tdbtnConfig" runat="server" colspan="2">
                            <div class="btnHold">
                                <asp:Button ID="btnConfigSubmit" runat="server" Text="Add" OnClientClick="return ValidatePropertyConfig();"
                                    CssClass="sendBtn" OnClick="btnConfigSubmit_Click" />
                                &nbsp;
                                <asp:Button ID="btnUpdateConfig" runat="server" OnClick="btnUpdateConfig_Click" OnClientClick="return ValidatePropertyConfig();"
                                    CssClass="sendBtn" Text="Update" Visible="False" />
                                <asp:Label ID="lblerrconfig" CssClass="errormsg" runat="server"></asp:Label>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <div class="pHold">
                                <div class="gridH">
                                    <asp:GridView ID="gvPropertyConfig" runat="server" AutoGenerateColumns="False" OnRowCommand="gvPropertyConfig_RowCommand"
                                        OnRowDataBound="gvPropertyConfig_RowDataBound">
                                        <Columns>
                                            <asp:TemplateField HeaderText="No Of Bedrooms" ItemStyle-CssClass="txtLT">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblno_of_bedrooms" runat="server" Text='<%# Eval("room_no") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Scalable Area" ItemStyle-CssClass="txtRT">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtscalable_area" runat="server" Text='<%# Eval("scalable_area") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblscalable_area" runat="server" Text='<%# Eval("scalable_area") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Carpet Area" ItemStyle-CssClass="txtRT">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtcarpet_area" runat="server" Text='<%# Eval("carpet_area") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblcarpet_area" runat="server" Text='<%# Eval("carpet_area") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Price/SqFt." ItemStyle-CssClass="txtRT">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtprice_per_sq_ft" runat="server" Text='<%# Eval("price_per_sq_ft") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblprice_per_sq_ft" runat="server" Text='<%# Eval("price_per_sq_ft") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="CC Price/SqFt." ItemStyle-CssClass="txtRT">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtcc_price_per_sq_ft" runat="server" Text='<%# Eval("cc_price_per_sq_ft") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblcc_price_per_sq_ft" runat="server" Text='<%# Eval("cc_price_per_sq_ft") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Total Price (in lacs)" ItemStyle-CssClass="txtRT">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txttotal_price" runat="server" Text='<%# Eval("total_price") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lbltotal_price" runat="server" Text='<%# Eval("total_price") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="" ItemStyle-CssClass="txtLT">
                                                <ItemTemplate>
                                                    <asp:ImageButton runat="server" ID="btnEditItem" CssClass="edBtn" ImageUrl="~/Admin/Includes/Images/edit.png"
                                                        ToolTip="Edit Item" CommandName="EditItem" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                                                    <asp:ImageButton runat="server" ID="btnDeletetem" CssClass="edBtn" ImageUrl="~/Admin/Includes/Images/delete.png"
                                                        CommandName="DeleteItem" ToolTip="Delete Item" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

解决方案

Use the "C" parameter in the ToString function, and make sure you set the globalaztion attributes.

string parseValueIntoCurrency(double number) {
   // set currency format
   string curCulture = Thread.CurrentThread.CurrentCulture.ToString();
   System.Globalization.NumberFormatInfo currencyFormat = new 
       System.Globalization.CultureInfo(curCulture).NumberFormat;

   currencyFormat.CurrencyNegativePattern = 1;

   return number.ToString("c", currencyFormat);
}

If you want to use a different Culture (say you're in USA, and you want the Indian format) then just use the appropriate CultureInfo element rather than getting it out of the current thread.

EXTRA INFO DUE TO OP EDIT

All right, what you're wanting to do to get this into your grid, is to create a PROTECTED function which takes in the number to be converted, and returns the converted string (this is basically the code above.

Now, on the ASPX side, you need to use that function in your grid view.
So, instead of this:

 <asp:TemplateField HeaderText="Total Price (in lacs)" >
   <EditItemTemplate>
      <asp:TextBox ID="txttotal_price" runat="server" 
                   Text='<%# Eval("total_price") %>' />
    </EditItemTemplate>
    <ItemTemplate>
       <asp:Label ID="lbltotal_price" runat="server" 
                  Text='<%# Eval("total_price") %>'> />
    </ItemTemplate>
 </asp:TemplateField>

you'll use this templatefield:

  <asp:TemplateField HeaderText="Total Price (in lacs)" >
    <EditItemTemplate>
       <asp:TextBox ID="txttotal_price" runat="server" 
                    Text='<%# Eval("total_price") %>' />
    </EditItemTemplate>
    <ItemTemplate>
        <%# parseValueIntoCurrency(Eval("total_price")) %>'>
     </ItemTemplate>
 </asp:TemplateField>

Note, two things. The first is that I'm still passing the UNFORMATTED value into the EDIT TEMPLATE, and that I'm not instantiating an extra LABEL in the ITEM TEMPLATE.

The reason I'm not doing the extra label, is because we just don't need it in there. That's just a bit more processor/memory overhead that you just don't need to incur.

As for passing the unformatted value to the text field, that's because it'll ultimately be easier to validate without having to parse out the commas and other string elements.

这篇关于格式十进制数印度货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆