I am trying to return a list of data along with the total number of records in a json format for extjs paging toolbar. extjs looks for "count" in order to calculate the total number of paging. This is the format I want.
{
"count": 1,
"listData": [
{
"LastName": "Beckham",
"FirstName": "David"
}
]
}
This is my method
public static List<myList> newRecords(int start, int limit)
{
List<myList> listData = new List<myList>();
using (SqlConnection con = SqlTools.GetSqlConnection())
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "id1_GetData";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@limit", SqlDbType.Int).Value = limit;
cmd.Parameters.Add("@start", SqlDbType.Int).Value = start;
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
myList list1 = new myList();
list1.LastName = reader["LastName"].ToString().Trim();
list1.FirstName = reader["FirstName"].ToString().Trim();
listData.Add(list1);
}
con.Close();
int count = countRecords(); //counts total number of records in db
var pagingData = (new
{
count,
listData
});
//return myList;
return new List<myList>(pagingData);
}
}
This way I get nothing... If I return myList, I only get the first page. please help