Posting a grid in form with checkboxes

4 posts, 1 answers
  1. Ale
    Ale avatar
    13 posts
    Member since:
    Dec 2013

    Posted 19 Mar 2014 Link to this post

    I tried this solution (http://www.telerik.com/support/code-library/submit-form-containing-grid-along-with-other-input-elements), for posting a grid inside an html forum and work correctly.
    But if I have a grid with checkboxes I don't understend how I can the true or false value.

    I've tried this solution, but doesn't work.

    columns.Bound(p => p.Inside).ClientTemplate(
    "<input type='checkbox' #= (Inside=== true) ? checked : '' # />" +
    "<input type='hidden' name='CAB[#= indexCAB(data)#].Inside' value='#= Inside#' />");

    Someone can help me.

    Thanks
  2. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 21 Mar 2014 Link to this post

    Hi,

    If the column value should be edited with the checkbox in the template then you should handle the checkbox click or change event and update the model. Please check this code-library which demonstrates this approach.

    Regards,
    Daniel
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  3. Ale
    Ale avatar
    13 posts
    Member since:
    Dec 2013

    Posted 28 Mar 2014 in reply to Daniel Link to this post

    Thanks Daniel.
    But now I have another problem with foreign key column binding.
    I want to show Unit of measure Name inside grid, and when I post the form I want to store unit of measure Id.
    I try to do this:

    columns.ForeignKey(p => p.UoMInitialId, (IEnumerable)ViewData["UoMs"], "UoMId", "Name").ClientTemplate("#= Name#" +
     "<input type='hidden' name='UoM[#= index(data)#].UoMId' value='#= UoMInitialId#' />");

    But I get error because Name doesn't exist.
    How can I do that?
  4. Answer
    Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 01 Apr 2014 Link to this post

    Hi,

    The foreignkey text field is not available in the data and by the default the foreignkey column uses the template to match the column value to the text. Since you are using a custom template, this logic should to be performed with custom code. I attached the code-library project modified to demonstrate one possible approach.

    Regards,
    Daniel
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
Back to Top