Hi
I am trying to add combobox in my grid when i click edit, But i am not able to do that, i am facing problems
1- I am passing my model in grid but all properties are string. Code is
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QTrac.DAL.AssetManagement.SearchRequest>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Detail </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <script id="assignedClientTemplate" type="text/x-jQuery-tmpl"> <option value="${RefAssignedClient_ID}">${RefAssignedClient_DESC}</option> </script> <script type="text/javascript"> var equipmentStatus = {}; <% foreach (QTrac.Models.EquipStatus es in (IEnumerable<QTrac.Models.EquipStatus>)ViewData["equipmentStatus"]) { %> equipmentStatus[<%= es.RefEqpStatusID %>] = "<%= es.EqpStatus %>"; <% } %> var searchClicked = false; jQuery(document).ready(function () { }) function OnResize(e) { // update the hidden values which will be posted as IDictionary<string,int> var grid = $('#Grid').data('tGrid'); $('#config_0__value').val(grid.$tbody.outerWidth()); var index = $.inArray(e.column, grid.columns) + 1; $('#config_' + index + '__value').val(e.newWidth); } function OnDataBinding(e) { if (!searchClicked) return false; var commaSeparatedClientBasket = $('#ClientBasket option:selected').not('option[value=\'-1\']').map(function () { return this.innerHTML; }).get().join(','); var commaSeparatedImportedClient = $('#ImportedClient option:selected').not('option[value=\'-1\']').map(function () { return this.innerHTML; }).get().join(','); e.data = { "request.FileCode": $('#FileCode').val(), "request.SerialNo": $('#SerialNo').val(), "request.TopLevelEquipment": $('#TopLevelEquipment').val(), "request.EquipmentState": $('#equipState option:selected').text(), "request.EquipmentStatus": $('#EquipmentStatus option:selected').text(), "request.DFP": $('#DFP option:selected').text(), "request.Active": $('#Active option:selected').val(), "request.OwnerSite": $('#OwnerSite').val(), "request.ControlSite": $('#ControlSite').val(), "request.Location": $('#Location').val(), "request.StampedFC": $('#StampedFC').val(), "request.StampedSN": $('#StampedSN').val(), "request.CustomsStatus": $('#CustomStatus option:selected').text(), "request.ImportType": $('#ImportType option:selected').text(), "request.ClientBasket": commaSeparatedClientBasket, "request.ImportClient": commaSeparatedImportedClient, "request.AssignedClient": $('#AssignedClient option:selected').text() }; } function onEdit(e) { // if ((typeof e.dataItem != 'undefined') && (e.dataItem != null)) { // $(e.form).find('#EqpStatus').data('tDropDownList').select(function(dataItem) { // return dataItem.Text == e.dataItem['EqpStatus']; // }); // } } </script> <div class="module" style="margin-bottom:10px"> <div class="caption"> <span>Asset Search</span> <img src="<%=Url.Content("/Content/rollup.gif") %>"/> </div> <div class="body"> <div id="colright" style="height:720px"> <div id="searchCriteria"><%Html.RenderAction("SearchCriteria", "SearchCriteria"); %></div> <br /> <table> <tr> <td> <input id="ButtonEdit" type="button" value="Edit" style="width:80px;"/> <input id="ButtonSave" type="reset" value="Save" style="width:80px" /> </td> </tr> </table> <% Html.Telerik().Grid<AssetManagementSearch>() .Name("Grid") .DataKeys(Keys => { Keys.Add(a => a.Equipment_ID); } ) .TableHtmlAttributes(new { style = "width:590px" }) .HtmlAttributes(new { @class = "myGrid" }) .Columns(columns => { columns.Command(commands => { commands.Edit(); //commands.Delete(); }).Width(130).Title("Action"); columns.Bound(o => o.FileCode).Width(85).Title("File Code"); columns.Bound(o => o.SerialNo).Width(75).Title("Serial No"); columns.Bound(o => o.RevLevel).Width(50).Title("Rev Level"); columns.Bound(o => o.EqpDescription).Width(150).Title("Description").ReadOnly(); columns.Bound(o => o.Manufacturer).Width(100); columns.Bound(o => o.BuildDate).Width(100).Title("Build Date"); columns.Bound(o => o.ControlSite).Width(100).Title("Control Site").ReadOnly(); columns.Bound(o => o.OwnerSite).Width(100).Title("Owner").ReadOnly(); columns.Bound(o => o.Location).Width(100).Title("Current Location").ReadOnly(); columns.Bound(o => o.EqpState).Width(100).Title("Eq. State"); columns.Bound(o => o.EqpStatus).Width(100).Title("Eq. Status").ClientTemplate("<#= equipmentStatus[EqpStatus] #>").Template(tp => { // We are mapping ID to description %> <%= ((IEnumerable<EquipStatus>)ViewData["EqpStatus"]).FirstOrDefault(e => e.EqpStatus == tp.EqpStatus).EqpStatus%> <% }); columns.Bound(o => o.DFP).Width(30); columns.Bound(o => o.Lawson_ID).Width(100).Title("Lawson NO"); columns.Bound(o => o.SAP_ID).Width(100).Title("SAP NO"); columns.Bound(o => o.PONumber).Width(150).Title("PO NO"); columns.Bound(o => o.PurchaseInvoiceNo).Width(150).Title("Purchase Inv. NO"); columns.Bound(o => o.SalesInvoiceNo).Width(70).Title("Sale Inv. NO"); columns.Bound(o => o.LegalEntity).Width(100).Title("Legal Entity"); columns.Bound(o => o.CustomsEntry).Width(100).Title("Customs Entry"); columns.Bound(o => o.CustomReceiptNo).Width(100).Title("Custom Receipt"); columns.Bound(o => o.CustomsStatus).Width(100).Title("Customs Status"); columns.Bound(o => o.ClientBasket).Width(100).Title("Client Basket"); columns.Bound(o => o.AssignedClient).Width(100).Title("Assigned Client"); columns.Bound(o => o.ImportClient).Width(100).Title("Import Client"); columns.Command(commands => commands.Edit()).Width(200); }) .DataBinding(dataBinding => dataBinding.Ajax() .Select("Select", "AssetManagement") .Insert("_InsertAjaxEditing", "AssetManagement") .Update("_SaveAjaxEditing", "AssetManagement") .Delete("_DeleteAjaxEditing", "AssetManagement")) .Scrollable(c => c.Height("430px")) .Resizable(resizing => resizing.Columns(true)) .Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn) .OrderBy(sortOrder => { sortOrder.Add(o => o.FileCode); sortOrder.Add(o => o.SerialNo); }) ) .Pageable(pager => pager.PageSize(20)) .ClientEvents(events => events.OnColumnResize("OnResize")) .ClientEvents(events => events.OnDataBinding("OnDataBinding")) .ClientEvents(events => events.OnEdit("onEdit")) .Render(); %> </div> </div> </div> </asp:Content>
2- i want to inject combobox in grid its code file is
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EqpStatus>" %>
<%=Html.Telerik().DropDownList()
.Name("EqpStatus")
.BindTo(new SelectList((IEnumerable)ViewData["equipmentStatus"], "RefEqpStatus_ID", "EqpStatus"))
%>
3- Model code is
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;
namespace QTrac.Models
{
using System;
using System.Collections.Generic;
public partial class EquipStatus
{
public int RefEqpStatusID { get; set; }
public int RefEqpStatusSiteID { get; set; }
[UIHint("EqpStatus"), Required]
public string EqpStatus { get; set; }
public Nullable<bool> Active { get; set; }
public string CreatedBy { get; set; }
public System.DateTime CreatedDate { get; set; }
public string LastModifiedBy { get; set; }
public System.DateTime LastModifiedDate { get; set; }
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace QTrac.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class AssetManagementSearch
{
public int Equipment_ID { get; set; }
public string FileCode { get; set; }
public string RevLevel { get; set; }
public string SerialNo { get; set; }
public int Equipment_SiteID { get; set; }
public string EqpDescription { get; set; }
public string EqpSiteCode { get; set; }
public Nullable<int> ToolHierarchy_ID { get; set; }
public int EquipmentType_ID { get; set; }
public Nullable<int> ProjectCodeMap_ID { get; set; }
public int RefEqpStatus_ID { get; set; }
public Nullable<int> RefEqpState_ID { get; set; }
public Nullable<int> RefManufacturer_ID { get; set; }
public Nullable<int> RefMaintGrp_ID { get; set; }
public int HoldingSite_ID { get; set; }
public int Ownership_ID { get; set; }
public string OwnerSite { get; set; }
public string ControlSite { get; set; }
public System.DateTime BuildDate { get; set; }
public string Lawson_ID { get; set; }
public string SAP_ID { get; set; }
public string CurrLocationType { get; set; }
public int CurrLocation_ID { get; set; }
public Nullable<bool> Loaned { get; set; }
public string PONumber { get; set; }
public string PurchaseInvoiceNo { get; set; }
public string SalesInvoiceNo { get; set; }
public string CustomsStatus { get; set; }
public string CustomsEntry { get; set; }
public string CustomReceiptNo { get; set; }
public string LegalEntity { get; set; }
public string DisposalInvoiceNumber { get; set; }
public string DisposalApprovedBy { get; set; }
public Nullable<System.DateTime> DisposalApprovedDate { get; set; }
public decimal ShockMaxLevel { get; set; }
public decimal ShockMaxDur { get; set; }
public decimal ShockTotal { get; set; }
public Nullable<decimal> HrsPump { get; set; }
public Nullable<decimal> HrsEDT { get; set; }
public Nullable<decimal> HrsSinceLastSL { get; set; }
public Nullable<System.DateTime> LastServiceDate { get; set; }
public Nullable<int> TempMax { get; set; }
public string CreatedBy { get; set; }
public System.DateTime CreatedDate { get; set; }
public string LastModifiedBy { get; set; }
public string EqpState { get; set; }
[UIHint("EqpStatus"), Required]
public string EqpStatus { get; set; }
public string Manufacturer { get; set; }
public System.DateTime LastModifiedDate { get; set; }
public string Location { get; set; }
public string SiteCode { get; set; }
public string parametername { get; set; }
public string eqpparamvalue { get; set; }
public Nullable<int> LastServiceLevel { get; set; }
public int WorkPack_ID { get; set; }
public Nullable<int> Customized_SiteID { get; set; }
public string UOMName { get; set; }
public int IsActive { get; set; }
public bool RMISTool { get; set; }
public int BatteryTool { get; set; }
public string DFP { get; set; }
public bool FatigueTool { get; set; }
public string RigName { get; set; }
public string ParentToolSet { get; set; }
public string ImmParentToolSet { get; set; }
public string Rental { get; set; }
public string BlockWO { get; set; }
public string STAMPEDFC { get; set; }
public string STAMPEDSN { get; set; }
public string ClientBasket { get; set; }
public string ImportClient { get; set; }
public string ImportType { get; set; }
public string AssignedClient { get; set; }
public string LastDateChange { get; set; }
public string AccountSite { get; set; }
}
}
4 - controller code is
using System;
using System.Web.Mvc;
using QTrac.BLL;
using QTrac.BLL.Extensions;
using QTrac.DAL;
using Telerik.Web.Mvc;
using QTrac.DAL.AssetManagement;
using QTrac.Models;
using System.Collections.Generic;
using System.Linq;
namespace QTrac.Web.Controllers
{
public class AssetManagementController : Controller
{
private IAssetManagementService assetManagementService;
public AssetManagementController(IAssetManagementService assetManagementService)
{
this.assetManagementService = assetManagementService;
}
public ActionResult Detail()
{
IEnumerable<EquipStatus> equipStatuses = assetManagementService.GetActiveEquipStatuses();
ViewData["equipmentStatus"] = equipStatuses.Select(e => new EquipStatus { RefEqpStatusID = e.RefEqpStatusID, EqpStatus = e.EqpStatus });
return View();
}
public ActionResult Index()
{
return View();
}
[GridAction]
public ActionResult Select(SearchRequest request)
{
var eresponse = new GridModel(assetManagementService.GetSearchResult(request));
return View(eresponse);
}
}
}
please check what i am doing wrong and what is its solution.
Thanks