tags:

views:

136

answers:

1

I could create a grid with telerik mvc

<% Html.Telerik().Grid(Model)
    .Name("ProductGrid")
    .Columns(columns => { 
                        columns.Bound(h => h.ProductName).Width("34%");
                        columns.Bound(h => h.Description).Width("60%");
                        columns.Bound(h => h.ProductID).Format(Html.ImageLink("Edit", "Products", new { Id = "{0}" }, "/Content/images/icon_edit.gif", "", new { Id = "edit{0}" }, null).ToString()).Encoded(false).Title("").Sortable(false).Width("3%");
                        columns.Bound(h => h.ProductID).Format(Html.ImageLink("Delete", "Products", new { Id = "{0}" }, "/Content/images/icon_delete.gif", "", new { onclick = string.Format("return confirm('Are you sure to delete this add on?');") },null).ToString()).Encoded(false).Title("").Sortable(false).Width("3%");
        })

    .EnableCustomBinding(true)
    .DataBinding(databinding => databinding.Ajax().Select("_Index", "ProductGrid"))
    .Pageable(settings => settings.Total((int)ViewData["TotalPages"])
    .PageSize(10))
    .Sortable()
    .Render(); %>

but I need to add a serial number column in telerik grid.How can i do this?

A: 

I think the best way to do this is to add a SerialNumber column to your Product class which is your model and than just add another bound column to the grid like this:

columns.Bound(h => h.SerialNumber)

If you pass a List of Products you can populate the SerialNumber column like this:

List<Product> products = GetList(); // Your method to get data here
int counter = 1;
products.ForEach(x => x.SerialNumber = counter++);

If you want to support consistent numbers with paging you have to calculate yourself the initial value of the counter valuable. For this purpose you must have the current page and page size.

Branislav Abadjimarinov
Thanks for your reply.If Iam adding a property "SerialNumber" in "Product" class.How can I increment its value for each row?
Jayaraj
It Works! Thank you very much.
Jayaraj