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

[Solved] Dropdownlist in Grid

0 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rhek
Top achievements
Rank 1
Rhek asked on 08 Aug 2011, 04:46 AM
Hello,

I am working on a MVC 3 application using Razor and VB. The grid is setup to batch edit. Without the dropdownlist the code displays the grid. I can't seem to get the code to work with a dropdownlist. I think my only problem is with the editor template of the dropdownlist. The line of code @model StoreId has StoreId underline and when hovering over the message "The type or namespace name "StoreId" could not be found (are you missing a using directive or an assembly reference?)". I thought the value of StoreId came from the column when the grid was defined.

If anyone sees the problem or any problem with the code please let me know.

I have been working through this demo: http://demos.telerik.com/aspnet-mvc/razor/grid/serveredittemplates/10253

Here is my code.

View:

@(Html.Telerik().
Grid(Model).
Name("Grid").Columns(Sub(columns)
columns.Bound(Function(model) model.ProductSkuId).ReadOnly()
columns.Bound(Function(model) model.ProductLine).ReadOnly()
columns.Bound(Function(model) model.ProductName).ReadOnly()
columns.Bound(Function(model) model.Flavor).ReadOnly()
columns.Bound(Function(model) model.StoreId)
columns.Bound(Function(model) model.DepartmentId)
columns.Bound(Function(model) model.CategoryId)
columns.Bound(Function(model) model.ProductGroupId).ReadOnly()
columns.Bound(Function(model) model.IsActive).Title("Active").ReadOnly()
End Sub).
ClientEvents(Function(events) events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError")).
DataBinding(Function(db) db.Ajax().Select("SelectProductGroup", "Masters").Update("SaveProductGroup", "Masters").Insert("SaveProductGroup", "Masters")).
DataKeys(Function(d) d.Add(Function(model) model.ProductSkuId)).
Editable(Function(e) e.Mode(GridEditMode.InCell)).
Filterable().
Groupable(Function(grouping) grouping.Groups(Function(groups) groups.Add(Function(model) model.ProductName))).
Pageable(Function(x) x.PageSize(ConfigurationManager.AppSettings("GridPageSize"))).
Sortable().
ToolBar(Function(t) t.SubmitChanges())
)

Controller:
#Region "PRODUCT - STORE/DEPARTMENT/CATEGORY"
 
    Function ProductGroupEdit() As ActionResult
      Dim ListOfItems As List(Of MastersModels.ProductGroupListItem) = MastersModels.LoadProductGroupList
      ViewBag.ListOfStores = MastersModels.LoadStoresDropdownList()
      Return View("ProductGroupEdit", ListOfItems)
    End Function
 
    <GridAction()>
    Public Function SelectProductGroup() As ActionResult
      Dim ListOfItems As List(Of MastersModels.ProductGroupListItem) = MastersModels.LoadProductGroupList
      ViewBag.ListOfStores = MastersModels.LoadStoresDropdownList()
      
Return View("ProductGroupEdit", New GridModel(ListOfItems))
    End Function
 
    <GridAction()>
    Public Function SaveProductGroup(<Bind(Prefix:="updated")> updatedList As IEnumerable(Of MastersModels.BrandListItem)) As ActionResult
 
      'Still working on code here
 
      Dim ListOfItems As List(Of MastersModels.ProductGroupListItem) = MastersModels.LoadProductGroupList
      Return View("ProductGroupEdit", New GridModel(ListOfItems))
 
    End Function
 
#End Region

Model
Public Class ProductGroupListItem
 
  <Display(Name:="Category:")>
  Public Property CategoryId As Int32 = 0
 
  <Display(Name:="Department:")>
  Public Property DepartmentId As Int32 = 0
 
  <Display(Name:="Brand Flavor:")>
  Public Property Flavor As String = String.Empty
 
  <Display(Name:="Active")>
  Public Property IsActive As Boolean = False
 
  <Display(Name:="Product Group Id:")>
  Public Property ProductGroupId As Int32 = 0
 
  <Display(Name:="Product Line:")>
  Public Property ProductLine As String = String.Empty
 
  <Display(Name:="Product Name:")>
  Public Property ProductName As String = String.Empty
 
  <Display(Name:="Product Id:")>
  Public Property ProductSkuId As Int32 = 0
 
  <UIHint("StoreDDL")>
  <Display(Name:="Store:")>
  Public Property StoreId As Int32 = 0
 
End Class

Editor Template: StoreDDL.cshtml
@model StoreId
@(Html.Telerik().DropDownList()       
  .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))       
  .BindTo(new SelectList(ViewBag.ListOfStores, "Id", "Name", Model.StoreId.ToString()))
)









Tags
Grid
Asked by
Rhek
Top achievements
Rank 1
Share this question
or