Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have MVC web grid with editable columns, but user is not like to edit all columns.Admin or users need to define certain columns to be editable and certain column not to editable dynamically.
(we have separate part for admin setting, here need to define which columns need to be editable)

Any one can help me with that..

What I have tried:

Grid View:

@grid.GetHtml(tableStyle: "webGrid", headerStyle: "header", alternatingRowStyle: "altColor",
columns:grid.Columns(
grid.Column("", style: "button",
format:
@<text>
<button class="edit-case read" id="@item.ReferenceID">Edit</button>

<button class="update-case edit" id="@item.ReferenceID">Update</button>
<button class="cancel-case edit" id="@item.ReferenceID">Cancel</button>
),
grid.Column("ParentSSN",canSort:false,
format:
@<text>
@item.ParentSSN
<input type="text" id="ParentSSN" value="@item.ParentSSN" class="edit" />

),
grid.Column("SSN"),
grid.Column("CAT"),
grid.Column("Name"),
grid.Column("MaritalStatus"),
grid.Column("PhoneNumber"),
grid.Column("FacilityID"),

grid.Column("FacilityAddress"),
grid.Column("County"),
grid.Column("ParentName"),
grid.Column("ParentAddress"),
grid.Column("PhoneNumber1"))


)

Jquery code:

<script type="text/javascript" >
$(function () {
$('.edit').hide();
$('.edit-case').on('click', function () {
var tr = $(this).parents('tr:first');
tr.find('.edit, .read').toggle();
});
$('.update-case').on('click', function (e) {
debugger;
e.preventDefault();
var tr = $(this).parents('tr:first');
id = $(this).prop('id');
var ParentSSN = tr.find('#ParentSSN').val();
var ddlcat = $('#ddlcat').val();
var ddlmarital = $('#ddlmarital').val();
var ddlparentSSN = $('#ddlparentSSN').val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Home/Edit",
data: JSON.stringify({ "id": id, "ParentSSN": ParentSSN, "CAT": ddlcat, "MaritalStatus": ddlmarital, "DllParentSSN": ddlparentSSN }),
dataType: "json",
success: function (data) {
debugger;
tr.find('.edit, .read').toggle();
$('.edit').hide();
debugger;
alert("success");
alert(data.ParentSSN);
alert(data);
tr.find('#ParentSSN').text(data.ParentSSN);
tr.find('#spanid').text(data.ParentSSN);
},
error: function (err) {
alert("error");
}
});
});
$('.cancel-case').on('click', function (e) {
e.preventDefault();
var tr = $(this).parents('tr:first');
var id = $(this).prop('id');
tr.find('.edit, .read').toggle();
$('.edit').hide();
});

});
</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900