Reputation: 3
i have a gridview in mvc and it works well. But i want my int column to have leading zeros.
For example: 1 becomes 01 and 10 becomes 10
Below is my sample code:
@Html.Grid(Model).Columns(columns =>
{
columns.Add(foo => foo.srfId).Titled("SRF NO").Sortable(true).Filterable(true);
})
Upvotes: 0
Views: 394
Reputation: 4170
there are two possible approaches one when you add new properties in your model itself with just getter
and add column for that property.
class MyModel
{
...
...
public int srfId { get; set;}
...
...
public string SrfIdFormatted
{
get { srfId.ToString("00"); }
}
...
}
then in your view you can do something -
@Html.Grid(Model).Columns(columns =>
{
columns.Add(foo => foo.SrfIdFormatted).Titled("SRF ID");
})
and second one is -- I remember we have Format
method on column
also. But I am not sure, try this as well, if it works for you.
columns.Add(c => c.SrfId).Format("{0:00}").Titled("SRF ID");
Upvotes: 1