This is a migrated thread and some comments may be shown as answers.
Bound Column Client Template Problem
2 Answers 58 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fred
Top achievements
Rank 1
Fred asked on 28 Dec 2011, 09:05 PM
Hi.  I am new with mvc.  I am a windows form vb.net experienced programmer doing the jump to a mvc project.

I am using the telerik extensions for mvc 3 and razor.

I have been able to do a lot in a short time, but now i am stuck when it comes times to replace a fkID in a bound column by its DisplayText from a dropdownList.

http://imageshack.us/photo/my-images/685/part1gt.png/

I also want to see the dropdown in the edit 

http://imageshack.us/photo/my-images/502/part2h.png/

i was able to put a dropdown list on my view which containes all the Villes but it was on top of the view, not in the columns

in my model, my CITY_ID is defined as such



        <DisplayName("Ville")> _
        <UIHint("Cities"), Required()>
        Public Property CITY_ID As Nullable(Of Integer)
            Get
                Return _cityId
            End Get
            Set(value As Nullable(Of Integer))
                _cityId = value
            End Set
        End Property



In my Controller, 

i feed this viewData before return the view

 ViewData("Cities") = _db.GEO_CITY.ToList

In my View

  
    Dim Cities = ViewData("Cities") i create a variable to hold my cities

and then i declare my grid

                                                    
    
    Html.Telerik.Grid(Model).Name("Grid") _
                           .ColumnContextMenu() _
                           .DataKeys(Sub(keys)
                                             keys.Add("Id")
                                     End Sub) _
                                 .ToolBar(Sub(commandes)
                                                  commandes.Insert.ButtonType(type).ImageHtmlAttributes(New With {.style = "margin-left:0"})
                                          End Sub) _
   .DataBinding(Sub(databinding)
                        databinding.Ajax() _
                            .Select("_AjaxIndex", "Fournisseurs") _
                            .Insert("_InsertAjaxEditing", "Fournisseurs") _
                            .Update("_AjaxEdit", "Fournisseurs") _
                            .Delete("_DeleteAjaxEditing", "Fournisseurs")
                End Sub) _
   .Columns(Sub(column)
                    column.Bound("Code").Width(100)
                    column.Bound("Nom").Width(100)
                    column.Bound("ADDRESS").Width(200)
                    column.Bound("CITY_ID").Width(100).ClientTemplate("<#= Cities.Name#>")
                    column.Bound("TEL").Width(100)
                    column.Bound("FAX").Width(100)
                    column.Bound("ZIPCODE").Width(100)
                    column.Command(Sub(commandes)
                                           commandes.Edit.ButtonType(type)
                                           commandes.Delete.ButtonType(type)
                                   End Sub).Width(180).Title("Commands")
            End Sub) _
        .Editable(Function(ee) ee.Mode(mode)) _
        .Pageable _
        .Scrollable _
        .Sortable() _
        .Render()
     

It all works except for the dropdownlist which is not displayed nor is it used.

Anyone can help ?

thanks a happy holidays


   

2 Answers, 1 is accepted

Sort by
0
Fred
Top achievements
Rank 1
answered on 29 Dec 2011, 03:32 AM
We i have figured out half of my problem.

I created a viewModel that only exposes the properties i need (to bypass the circular reference problem) and used automapper 
to flatten the model and retrieve the description of the foreign key.

Works well if all i need is to show the data.... but if i want to edit it, i still got work to do

0
zhang
Top achievements
Rank 1
answered on 29 Dec 2011, 04:19 AM
this is a example from  the book pro mvc:

@model Role 
           
@model Role
           
<select id="Role" name="Role">
    @foreach (Role value in Enum.GetValues(typeof(Role))) {
        <option value="@value" @(Model == value ? "selected=\"selected\"" : "")>@value
            </option>
    }
</select>
Tags
Grid
Asked by
Fred
Top achievements
Rank 1
Answers by
Fred
Top achievements
Rank 1
zhang
Top achievements
Rank 1
Share this question
or