This is a migrated thread and some comments may be shown as answers.

Bit field not displaying "Yes" or "No"

7 Answers 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 14 Jul 2014, 05:42 PM
I added ClientTemplate() to my column so that I can display the value as "Yes" and "No" rather than the default "True" and "False".
columns.Bound(p => p.IsActive).ClientTemplate("#= IsActive ? 'Yes': 'No'
#").Title("Is Active").Width(100);<BR>

However, the grid is still displaying True and False.

What am I missing?

Thanks,

7 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 16 Jul 2014, 07:27 AM
Hello Bruce,


The template syntax looks correct. Is the current Grid using an Ajax or Server dataSource? If it is using a server bound dataSource, you should use the Template() method and a server template instead.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bruce
Top achievements
Rank 1
answered on 17 Jul 2014, 08:20 PM
Yes, I'm using a server side data source.

Please send me a link showing how to do this using the Template() method.

Thanks,

0
Dimiter Madjarov
Telerik team
answered on 18 Jul 2014, 08:42 AM
Hello Bruce,


The Template method accepts razor delegate as a parameter. Here is a sample implementation of the conditional logic in it.
E.g.
columns.Bound(p => p.IsActive).Template(@<text>@(item.IsActive? "Yes" : "No")</text>);

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bruce
Top achievements
Rank 1
answered on 18 Jul 2014, 01:58 PM
Thanks!

However, I have a question with the "item.IsActive" section of the code.

What is item?  (or is it @item)?  Neither of them work.  Nor does using p.IsActive.

Thanks again!
0
Dimiter Madjarov
Telerik team
answered on 18 Jul 2014, 02:36 PM
Hi Bruce,

item is the parameter in the templated razor delegate that refers to the current Grid item. Could you send me an isolated example, which demonstrates the problem, as I am not sure why the solution is not working on your side?

I am looking forward to hearing from you.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bruce
Top achievements
Rank 1
answered on 18 Jul 2014, 02:41 PM
Here is the view.  The p in "(p.IsActive ?" has a red squiggly line underneath it.  The error is: "C#: Unknown entity 'p'".

Thanks,  - Bruce

@model IEnumerable<DataModel.tbl_spm_phonebook>

@{
ViewBag.Title = "GMAM Phonebook";
 
}

<hgroup class="title">
<h1>@ViewBag.Title</h1>
</hgroup>


@(Html.Kendo().Grid(Model)
.Name("Phonebook")
.Columns(columns =>
{
columns.Bound(p => p.FullName).Title("Full Name").Width(150);
columns.Bound(p => p.GMAMID).Title("NAM ID").Width(100);
//columns.Bound(p => p.IsActive).ClientTemplate("#= IsActive ? 'Yes': 'No' #").Title("Is Active").Width(100);
columns.Bound(p => p.IsActive).Template(@<text>@(p.IsActive? "Yes" : "No")</text>);
// columns.Template(d => @Html.ActionLink("Edit", "Edit", new { id = d.PhonebookID, }));
columns.Command(command => { command.Edit(); }).Width(150);
columns.Template(d => @Html.ActionLink("Details", "Details", new { id = d.PhonebookID, }));
})

.DataSource(dataSource => dataSource
.Server()
.Sort(sort => sort.Add("FullName").Ascending())
.Model(model => model.Id(p => p.PhonebookID))
.Create(update => update.Action("EditingPopup_Create", "Grid"))
.Read(read => read.Action("EditingPopup_Read", "Grid"))
.Update(update => update.Action("editingPopup_Update", "Grid"))
)
.Pageable()
.Sortable()
.Scrollable(scr => scr.Height(400))
.Filterable()
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.ToolBar(toolbar => toolbar.Create())
)

@Html.ActionLink("Create New", "Create")

-----------------------------------------------------------------------
Here is the controller (top part):

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataModel;

namespace SpreadMaster.Controllers
{
public class PhonebookController : Controller
{
private SpreadMasterEntities db = new SpreadMasterEntities();

//
// GET: /Phonebook/

public ActionResult Index()
{
SpreadMasterEntities contextDM = new SpreadMasterEntities();
var phonebook = contextDM.tbl_spm_phonebook;

return View(phonebook.ToList());
}
0
Dimiter Madjarov
Telerik team
answered on 21 Jul 2014, 12:04 PM
Hi Bruce,


As stated in the previous answer, the item keyword is mandatory to use instead of p in the current case as it is used as a parameter in templated delegates. If the problem with the conditional statement persists, could you please send me a runnable isolated example, which demonstrates it, so I could inspect it locally?

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Bruce
Top achievements
Rank 1
Share this question
or