We help IT Professionals succeed at work.

How to limit the display of records in Datalist?

sivakugan
sivakugan asked
on
Hi all,
I'm using Datalist. I want to limit the display of records. How can I do that?.
I mean if i wanna display only 10 records. What should I do for that?
Note- I'm not asking for paging in Datalist. I don't want that for my application.
Comment
Watch Question

You can achieve the task with the help of stored procedure.
It is much efficient and faster than gridview paging

Check the articles
http://www.codeproject.com/KB/webforms/GridViewCustomPaging.aspx
http://www.beansoftware.com/ASP.NET-Tutorials/Paging-Stored-Procedures.aspx

Hope this will help you
Kaushal AroraTechnical Analyst

Commented:
As per what i understand from your question is that you dont want paging. Then if you want to limit your dataset to 10 records with you want to populate your datalist, then i can suggest you one thing. Use the overloaded constructor of the dataadapter for getting only first 10 ten records or any 10 records you want. Have a look at the sample here:

http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlcedataadapter.rowupdating(VS.80).aspx

Hope this helps you.

Author

Commented:
Hi KaushalArora,

If i wanna display 15 records in DESC order.  What should I do here?

DataSet ds = new DataSet();
   adp.Fill(ds, 0, 5, "Table");

Technical Analyst
Commented:
you need to add order by clause in the query with which you are filling your dataset using dataadapter.
like:

select userid,username from usertable order by userid desc

this query will give me recently added userid's and then i can fill 15 using adapter the way i sent you before.

Author

Commented:
Thanks Nice easy solution.