0

I am kind of a newbie to MVC and Telerik and working on a project that involves both of them, the problem am facing currently is: Am using teleirk Grids extension with Grid Method (DataTable) bound to a DataTable:

<% var table = ViewData["NewDesigns"] as DataTable;

Html.Telerik() .Grid(table) .Name("oi") .Pageable(pager => pager.PageSize(100)) .Groupable() .Sortable() .Columns(columns => { columns.Bound(r => r.category).Title("Category"); }) .Render(); %>

The grid is being displayed fine but there are two things that I want to do:

  1. Change the column name to my custom heading/title
  2. Eid Datatable content before printing it in a grid: For e.g.: if id column has a value ‘21’, I want to print it in as hyper-link 21

I've spent time in telerik help files and learned a lot but not able to find answer of these, ld appericiate if someone here could help me out.

DataTable Object:

    ordr    {myprod.Models.Orders}  myprod.Models.Orders addrss null    string cntact   null    string custmrNam    null    string dlivrdn  null    string dsignr   null    string dsignId  null    string mail null    string id   null    string rdrCd null   string rdrdn    null    string quantity null    string siz  null    string status   null    string ttalPric null    string twn  null    string usrId    null    string'

1 Answer 1

0

The following example with custom titles and custom templates might help:

Html.Telerik()
    .Grid(table)
    .Name("ordersInum")
    .Columns(columns =>
    {
        columns.Bound(typeof(Int32), "ID").Title("Row ID").Template(Html.ActionLink(item.ID, "Detail", new { r.ID }));
        columns.Bound(typeof(string), "Name").Title("Product").Template(@<text>
                <img src="images/product.png" />
                @item.Name
            </text>);
        columns.Bound(typeof(Double), "Price").Title("Price in $");
        columns.Bound(typeof(DateTime?), "OrderDate").Format("{0:MM/dd/yyyy}").Width(80);
    })
    .Pageable(pager => pager.PageSize(100))
    .Groupable()
    .Sortable()
    .Render();
Sign up to request clarification or add additional context in comments.

6 Comments

Thank-you for reply, But adding this line[.Columns(columns => { columns.Bound(r => r.price).Title("Price in $"); })] is giving this compilation error: "CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type"
@Maven: I wasn't able to test my sample because I didn't have a matching data source to bind to the grid. Either start with a working page and work step by step by adding small pieces from my sample and fixing all the problems that occur, or paste all the details of your data table and the full grid definition that doesn't work.
yea sure: :) <% var table = ViewData["NewDesigns"] as DataTable; Html.Telerik() .Grid(table) .Name("oi") .Pageable(pager => pager.PageSize(100)) .Groupable() .Sortable() .Columns(columns => { columns.Bound(r => r.category).Title("Category"); }) .Render(); %>
DataTable Object: 'ordr {myprod.Models.Orders} myprod.Models.Orders addrss null string cntact null string custmrNam null string dlivrdn null string dsignr null string dsignId null string mail null string id null string rdrCd null string rdrdn null string quantity null string siz null string status null string ttalPric null string twn null string usrId null string'
@Maven: Would you mind adding these two pieces to your question. It's not really readable as a comment.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.