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.
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: @
</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.
0 comments:
Please let me know your view