Combobox Datasource read

2 posts, 0 answers
  1. Xinzhou
    Xinzhou avatar
    8 posts
    Member since:
    May 2014

    Posted 03 Jun 2014 Link to this post

    Here's my Combobox in Razor format:

     .DataSource(source =>
               source.Read(read =>
                   read.Action("GetBuyQuarter", "BuyBuilder"); //Set the Action and Controller name
               .ServerFiltering(true); //If true the DataSource will not filter the data on the client.
       .SelectedIndex(0) //Select first item.

    My Controller GetBuyQuarter Function:

        public ActionResult GetBuyQuarter([DataSourceRequest]DataSourceRequest request)
                DataTable dt = new DataTable();
                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                Dictionary<string, object> row = default(Dictionary<string, object>);

                string conn = ConfigurationManager.ConnectionStrings["DevConnString"].ConnectionString;
                using (SqlConnection con = new SqlConnection(conn))
                    using (SqlCommand cmd = new SqlCommand("select * from QTRLIst  where(startdate > DateAdd(yy, -2, getdate()) And startdate < DateAdd(yy, 1, getdate())) order by StartDate desc ", con))
                        SqlDataAdapter da = new SqlDataAdapter(cmd);

                        foreach (DataRow dr in dt.Rows)
                            row = new Dictionary<string, object>();
                            foreach (DataColumn col in dt.Columns)
                                row.Add(col.ColumnName, dr);
                return Json(rows, JsonRequestBehavior.AllowGet);}

    I do not see any data in the combobox.  If i changed the return to Json(dt.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

    i get this error. Unhandled exception at line 11, column 15864 in http://localhost:52493/Scripts/kendo/2014.1.415/kendo.all.min.js

    0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'slice'

  2. Daniel
    Daniel avatar
    2177 posts

    Posted 05 Jun 2014 Link to this post


    You should set the row value instead of the entire row e.g.
    foreach (DataColumn col in dt.Columns)
        row.Add(col.ColumnName, dr[col.ColumnName]);

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top