This is a migrated thread and some comments may be shown as answers.

Combobox Datasource read

1 Answer 169 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Xinzhou
Top achievements
Rank 1
Xinzhou asked on 03 Jun 2014, 02:19 PM
Here's my Combobox in Razor format:

@(Html.Kendo().ComboBox()
    .Name("cmbQuarter") 
    .DataTextField("QTR") 
    .DataValueField("QTR") 
 .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))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    con.Close();

                    foreach (DataRow dr in dt.Rows)
                    {
                        row = new Dictionary<string, object>();
                        foreach (DataColumn col in dt.Columns)
                        {
                            row.Add(col.ColumnName, dr);
                        }
                        rows.Add(row);
                    }
                }
            }
            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'
















1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 Jun 2014, 11:52 AM
Hi,

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]);
}


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ComboBox
Asked by
Xinzhou
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or