Thursday, 27 July 2017

Display Currency Value With Rupee Symbole In Asp.Net MVC Using C#.Net

7/27/2017 - By Pranav Singh 0

This article will show you how you can display or bind the price of an item in asp.net mvc  webgrid with rupee symbol using c#.net. In this I have displayed the item price with rupee symbol. I have used CultureInfo class for managing the currency symbol.

So for this article first we will create a new ap.net mvc  application and add the model class file. After this we will add the below code in it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVC_Demos.Models
{
    public class ItemMasterModel
    {
        public List<ItemMaster> CountryList { get; set; }
    }
    public class ItemMaster
    {
        public int ID { get; set; }
        public string ItemName { get; set; }
        public int ItemCount { get; set; }
        public int ItemPrice { get; set; }
    }
}

After this we will add a controller class file and add  the below code in it.

using MVC_Demos.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC_Demos.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        [HttpGet]
        public ActionResult Index()
        {
            ItemMasterModel _countryModel = new ItemMasterModel();
            _countryModel.CountryList = GetCountryList();
            return View(_countryModel);
        }

        ///

        /// Country list
        ///
        public List<ItemMaster> GetCountryList()
        {
            List<ItemMaster> _country = new List<ItemMaster>();
            _country.Add(new ItemMaster { ID = 1, ItemName = "Item 1", ItemCount = 1, ItemPrice = 234456 });
            _country.Add(new ItemMaster { ID = 2, ItemName = "Item 2", ItemCount = 2, ItemPrice = 12765 });
            _country.Add(new ItemMaster { ID = 3, ItemName = "Item 3", ItemCount = 1, ItemPrice = 456754 });
            _country.Add(new ItemMaster { ID = 4, ItemName = "Item 4", ItemCount = 3, ItemPrice = 3457 });
            return _country;
        }
    }
}

       

In above code I have prepared the code to prepare the data for binding to web grid. Now create the view and add the below code.

@model MVC_Demos.Models.ItemMasterModel
@{
    ViewBag.Title = "Asp.Net MVC : Display Currency Value With Rupee Symbole Using C#.Net";
}



@using (Html.BeginForm("Index", "Home"))
{
    <table width="100%" cellpadding="5" cellspacing="2" border="0" style="background-color: White;">
        <tr>
            <td>
                @{
    var grid = new WebGrid(source: Model.CountryList,
    rowsPerPage: 10,
    canSort: true);

                }
                @grid.GetHtml(
                    tableStyle: "gridtable",
                    alternatingRowStyle: "even",
                    columns: grid.Columns(
                    grid.Column("CountryName", "CountryName"),
                    grid.Column("Population", "Population"),
                    grid.Column("ItemPrice", header: "Item Price", format: @@item.ItemPrice.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("hi-IN")))

            </td>
        </tr>
    </table>
}

In above code just check the highlighted part of the code. In this I have passed the Globalization.CultureInfo. This is used for passing for which culture we want to convert the item. Now we have done run the application to check the output.




About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top