Neo Neo - 21 days ago 8
ASP.NET (C#) Question

display only first 10 records from array using c# jquery

Index.aspx

$(document).ready(function () {

$.ajax({
type: "POST",
url: "Index.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {

$.each(msg.d, function (index, value) {
$('#myDiv').html(value.Email);
});


}
})
return false;
});


Index.aspx.cs

[WebMethod]

public static IEnumerable<TemperatureEntity> GetData()
{
//return array data



I have traverse through array and want to display it in tabular format on html like email,phonenumber.
enter image description here
enter image description here

Answer

If you want to do it exaclty on the client side then check the slice() jQuery function

You should modify your code as following:

var slicedData = msg.d.slice(0, 10);
$.each(slicedData, function (index, value) {
                    var html = $('#myDiv').html();
                    html += value.Email;
                    html += value.PhoneNumber;
                    $('#myDiv').html(html + '<br />');
                });

But if you can modify the resulting array on the server side - do it on server side with Linq method Take(10);

Comments