Вопрос

Is it posible to use row specific content into HtmlAttributes?

I got this cell with its content (o.ArrivalTime), when i move my mouse over it i'll like it to show the content from a other element (o.Note) in a tooltip

I tried this but it will not accept the o.Note

columns.Bound(o => o.ArrivalTime)
  .Title("Arrival Time")
  .Template(o =>
        {%><%=(o.ArrivalTime < Convert.ToDateTime("2000-01-01")) ? "?" : o.ArrivalTime.ToString()%><%})
  .Width(140)
  .HtmlAttributes(new {title = o.Note })
  ;
Это было полезно?

Решение

Rather than using HtmlAttributes, you can do this inside Template.

columns.Bound(o => o.ArrivalTime)
  .Title("Arrival Time")
  .Template(o =>
    {%><div title="<%= o.Note %>"><%=(o.ArrivalTime < Convert.ToDateTime("2000-01-01")) ? "?" : o.ArrivalTime.ToString()%></div><%})
  .Width(140)
  ;

Другие советы

Please take a look at the following example.

Grid - Server Templates

In this example the first column uses a templating mechanism to create the column. In similar way you can create a template for your column and then use the different columns while defining the template. Here is the code snippet from the demo:

<% Html.Telerik().Grid(Model)
    .Name("Grid")
    .Columns(columns => 
    {
        //Template column. The grid displays the HTML defined by the argument.
        columns.Template(c => {
        %>
            <img 
                alt="<%= c.CustomerID %>" 
                src="<%= Url.Content("~/Content/Grid/Customers/" + c.CustomerID + ".jpg") %>" 
              />
        <%
        });
        //Regular databound column. The grid displays the value of the CustomerID property.
        columns.Bound(c => c.CustomerID);
    })
    .Render();

%>

Hope this was helpful to your question.

Lohith (Tech Evangelist, Telerik India)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top