0

How i can make my webgrid editable if my model and view is like below code. I want to provide option to edit, delete, save & cancel.

1- My model

public class CurrentReport
    {       
        public IEnumerable<TablesField> OTablesFields { get; set; }
        public List<dynamic> dataField { get; set; }
    }

2- My view

@model WDCS.MODELS.CurrentReport

<div id="PartialPage">

@{
    var grid = new WebGrid( Model.dataField , rowsPerPage: 5, canPage: true, canSort: true, ajaxUpdateContainerId: "Grid");

        List<webgridcolumn> cols = new List<webgridcolumn>();

        foreach (var clm in Model.OTablesFields)
        {
            cols.Add(grid.Column(clm.fieldName, clm.displayName));        
        }        

    }


    <div id="Grid">
          @grid.GetHtml(
                        tableStyle:"webGrid",
                        headerStyle:"header",
                        alternatingRowStyle:"alt",
                        columns:cols           
                       )

    </div>

</div>
Rahul Kumar
  • 21
  • 1
  • 7

1 Answers1

0

To make a WebGrid editable, there are some approaches, one of them is putting editable and static HTML elements in each row and make them visible or invisible in each state by some JavaScript codes. Another approach is invoking a jQuery dialog that contained a form.

The both approaches are popular and it is up to you to choose one of them. The two links below describe them in detail.

Inline Editing With The WebGrid

WebMatrix and jQuery Forms Part 2 - Editing Data

Abbas Amiri
  • 3,074
  • 1
  • 23
  • 23
  • thanks for your reply... I already go through these option but in my case problem is the column value is not predefind – Rahul Kumar Dec 06 '13 at 12:45
  • You're welcome; You can find properties of a dynamic object by reflection; http://stackoverflow.com/questions/8631546/get-property-value-from-c-sharp-dynamic-object-by-string-reflection might be helpful. – Abbas Amiri Dec 06 '13 at 13:27