Neo
Neo

Reputation: 16219

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

Upvotes: 0

Views: 1203

Answers (1)

Mikhail Tulubaev
Mikhail Tulubaev

Reputation: 4261

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

Upvotes: 1

Related Questions