Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3 JQGrid
Hii to all,
   I Have a requirement that i need to retrive  one r more table's data from DataBase (SQLServer)& display in a Jqgrid.Up to here i have done using Linq Joins&EntityFramework,and one more requirement where i strucked is,here in Jqgrid i have made Multiselect to True,after displaying the table data in Jqgrid the respective checked row's data i need to get in another view say Editable view where i need to dispaly this row data in Textboxes in Editable mode,here user will update the records present in Textboxes and when he press Updata button,the records should be updated to DataBase& also we need to redirect to previous View(after clicking update button in Editable View)
 i.e Jqgrid view & display the modified records in Jqgrid.
Here is my Jqgrid View code  say "GetTablesData":-
@model MVCLINQJoins.Models.TableData
<link href="@Url.Content("~/Content/themes/base/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/JS/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/JS/jquery.jqGrid.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/JS/grid.locale-en.js")" type="text/javascript"></script>
@{
    ViewBag.Title = "GetTablesData";
}
<h2>
    GetTablesData</h2>
<script type="text/javascript">
    var mdata = []
</script>
@foreach (var item in Model.getEmployeeDetails)
{
    <script type="text/javascript">
        row = { EmployeeID: '@item.EmployeeId', EmpName: '@item.EmpName', Designation: '@item.Designation', Salary: '@item.Salary', MobileNo: '@item.MobileNo', Email: '@item.Email' };
        mdata.push(row);
    </script>
}
<table id="emp-data-grid">
</table>
<script type="text/javascript">
    $("#emp-data-grid").jqGrid({
        datatype: "local",
        data: mdata,
        colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email"],
        colModel: [
                { name: "EmployeeID", index: "EmployeeID", editable: true, edittype: "checkbox", editoptions: { value: "Yes:No"} },
                { name: "EmpName", index: "EmpName" },
                { name: "Designation", index: "Designation" },
                { name: "Salary", index: "Salary", sorttype: "int" },
                { name: "MobileNo", index: "MobileNo", sorttype: "int" },
                { name: "Email", index: "Email" }
            ],
        shrinkToFit: true,
        multiselect:true,
        caption: "Employee List"
 
    });
 

</script>
    @Html.ActionLink("EDIT", "Edit")
when he click on above Edit link,i need to get the respective rows data to Edit View.
Here is My Controller Code:-
public ActionResult GetTablesData()
        {
            TableData model = new TableData();
            model.getEmployeeDetails = new List<Employee>();
            GetDataFromDB(model);
            return View(model);
        }
 
        private static void GetDataFromDB(TableData model)
        {
            using (personalEntities2 db = new personalEntities2())
            {
                var emply = (from empd in db.empdetails
                             join empp in db.emppersonals on empd.empid equals empp.empid
                             orderby empd.empid
                             select new
                             {
                                 empd.empid,
                                 empd.ename,
                                 empd.designation,
                                 empd.salary,
                                 empd.deptno,
                                 empp.mobileno,
                                 empp.email
                             });
                foreach (var item in emply)
                {
                    Employee ed = new Employee();
                    ed.EmployeeId = item.empid;
                    ed.EmpName = item.ename;
                    ed.Designation = item.designation;
                    ed.Salary = item.salary;
                    ed.DeptNo = item.deptno;
                    ed.MobileNo = item.mobileno;
                    ed.Email = item.email;
                    model.getEmployeeDetails.Add(ed);
                }
 
            }
        }
        public ActionResult Edit(Employee model,int id)
        {
 
          return View(model);
        }
Please guide me how to achieve my requirement along with Controller code.Thanks in advance
 
Thanks
Ramu
Posted 22-May-13 23:06pm

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 295
1 OriginalGriff 274
2 Shweta N Mishra 216
3 PIEBALDconsult 184
4 CPallini 155
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100