Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pass selected combobox value to controller and bind the data from controller to view in mvc3 using jquery
    primarykey
    data
    text
    <p>I'm developing site using html5 and kendo ui in asp.net with MVC3 i have got a problem that how to send value when combobox selected value should pass to model and the data from Database should bind to the grid in the view</p> <p>here is the code in the view</p> <pre><code>&lt;h3&gt; Employee Name &lt;/h3&gt; &lt;input id="comboBox1" /&gt; &lt;h3&gt; Employee Details using remote &lt;/h3&gt; &lt;div id="empgrid"&gt; </code></pre> <p></p> <pre><code>var dataSource = new kendo.data.DataSource({ transport: { read: "/Home/GetData", update: { url: "/Products/Update", type: "POST" }, destroy: { url: "/Products/Destroy", type: "POST" }, create: { url: "/Products/Create", type: "POST" } }, schema: { model: { id: "eid", fields: { eid: { //this field will not be editable (default value is true) editable: false, // a defaultValue will not be assigned (default value is false) nullable: true }, ename: { validation: { //set validation rules required: true } }, age: { //data type of the field {Number|String|Boolean} default is String type: "number", validation: { required: true, min: 25 } }, salary: { type: "long", validation: { min: 5000 } } } } }, // determines if changes will be send to the server individually or as batch batch: true //... }); $(document).ready(function () { $("#comboBox1").kendoComboBox({ index: 0, dataTextField: "ename", dataValueField: "eid", filter: "contains", dataSource: { type: "json", serverFiltering: true, serverPaging: true, pageSize: 5, transport: { read: "Home/GetData" } } }); $("#empgrid").kendoGrid({ pageable: true, toolbar: ["create", "save", "cancel"], editable: true, dataSource: dataSource, columns: [ { title: 'Employee Id', field: 'eid', width: '35%', sortable: true }, { title: 'Employee Name', field: 'ename', width: '45%', flex: 1, sortable: true }, { title: 'Age', field: 'age', width: '25%', flex: 1, sortable: true }, { title: 'Salary', field: 'salary', width: '45%', flex: 1, sortable: true } ], sortable: true }); $("#get").click(function () { var customDataListId = $("#comboBox1").data("kendoComboBox"); $.getJSON('&lt;%= Url.Action("PutData", "Grid")%&gt;', { eid: ""+customDataListId.text()+"" }, function (result) { var customDataList = $('#empgrid'); customDataList.empty(); customDataList.append(result.PutData); }); alert(customDataListId.text()); }); </code></pre> <p>});</p> <p></p> <p>In the Controller the following code</p> <pre><code> public ActionResult Index() { var products = new Movie().GetData(); ViewData["products"] = products; return View(); } [AcceptVerbs(HttpVerbs.Get)] public JsonResult GetData() { var emp = new Movie().GetData(); return Json(emp, JsonRequestBehavior.AllowGet); } [HttpPost] public ActionResult PutData(string ename) { var emp = new Movie().PutData(ename); return Json(emp, JsonRequestBehavior.AllowGet); } </code></pre> <p>In the Model the following code</p> <pre><code> DataTable Datatable = new DataTable(); DataSet Dataset = new DataSet(); public List&lt;EmpPro&gt; PutData(string ename) { string str = "Data Source=HARAVEER-PC\\SQLEXPRESS;Initial Catalog=Examples;Integrated Security=true"; SqlConnection connection = new SqlConnection(str); SqlCommand command = connection.CreateCommand(); command.CommandText = "select * from Emp where eid="+ename; SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = command; DataSet ds = new DataSet(); try { connection.Open(); sda.Fill(ds); List&lt;EmpPro&gt; objlist = new List&lt;EmpPro&gt;(); for (int i = 0; i &lt; ds.Tables[0].Rows.Count; i++) { EmpPro objemp = new EmpPro(); objemp.eid = Convert.ToInt32(ds.Tables[0].Rows[i]["eid"]); objemp.ename = ds.Tables[0].Rows[i]["ename"].ToString(); objemp.age = Convert.ToInt32(ds.Tables[0].Rows[i]["age"]); objemp.salary = Convert.ToInt64(ds.Tables[0].Rows[i]["salary"]); objlist.Add(objemp); } //return ds.Tables[0]; return objlist; } catch { return null; } finally { if (connection.State != ConnectionState.Closed) connection.Close(); } } public List&lt;EmpPro&gt; GetData() { //string str = "Data Source=(local);Initial Catalog=Student;Persist Security Info=True;Integrated Security=SSPI"; string str = "Data Source=HARAVEER-PC\\SQLEXPRESS;Initial Catalog=Examples;Integrated Security=true"; SqlConnection connection = new SqlConnection(str); SqlCommand command = connection.CreateCommand(); command.CommandText = "select * from Emp"; SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = command; DataSet ds = new DataSet(); try { connection.Open(); sda.Fill(ds); List&lt;EmpPro&gt; objlist = new List&lt;EmpPro&gt;(); for (int i = 0; i &lt; ds.Tables[0].Rows.Count; i++) { EmpPro objemp = new EmpPro(); objemp.eid = Convert.ToInt32(ds.Tables[0].Rows[i]["eid"]); objemp.ename = ds.Tables[0].Rows[i]["ename"].ToString(); objemp.age = Convert.ToInt32(ds.Tables[0].Rows[i]["age"]); objemp.salary = Convert.ToInt64(ds.Tables[0].Rows[i]["salary"]); objlist.Add(objemp); } //return ds.Tables[0]; return objlist; } catch { return null; } finally { if (connection.State != ConnectionState.Closed) connection.Close(); } } } public class EmpPro { public int eid { get; set; } public string ename{get;set;} public int age{set;get;} public long salary { set; get; } } </code></pre> <p>please can any help me out</p> <p>thanks and regards </p> <hr>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload