$("#grid").kendoGrid({
toolbar: ["excel"],
excel: {
fileName: "Data_Export.xlsx",
},
dataSource: {
transport: {
read: {
//$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: "Home.aspx/GetData",
data: '{}',
success: function (response) {
alert("hi");
},
error: function (response) {
alert("error");
}
//})
},
},
schema: {
model: {
fields: {
iID: { type: "string" },
szName: { type: "string" }
}
}
},
pageSize: 20,
},
height: 550,
groupable: true,
selectable: true,
sortable: true,
filterable: {
messages: {
clear: "Clear filter",
},
mode: "row"
},
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "iID",
title: "iID",
width: 140,
filterable: {
cell: {
showOperators: true
}
}
}, {
field: "szName",
title: "szName",
width: 140,
filterable: {
cell: {
showOperators: true
}
}
}]
});
/////////////////////////////////////////////////////////////////////////////////////
[WebMethod()]
public static List<Records> GetData()
{
SqlDataReader dr;
List<Records> recordsList = new List<Records>();
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["test"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select [iID],[szName] from [Sprinter].[tblEmployee] ";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
while (dr.Read())
{
string ID = dr["iID"].ToString();
string Name = dr["szName"].ToString();
recordsList.Add(new Records
{
iID = ID,
szName = Name,
});
}
}
}
}
return recordsList;
}
Ajax call does not execute success or error functions. The grid is empty. Can you please help what I am doing wrong.