ASP.Net: How to do pagination with a Repeater? - asp.net

I'm using the Repeater control on my site to display data from the database. I need to do pagination ("now displaying page 1 of 10", 10 items per page, etc) but I'm not sure I'm going about it the best way possible.
I know the Repeater control doesn't have any built-in pagination, so I'll have to make my own. Is there a way to tell the DataSource control to return rows 10-20 of a much larger result set? If not, how do I write that into a query (SQL Server 2005)? I'm currently using the TOP keyword to only return the first 10 rows, but I'm not sure how to display rows 10-20.

You have to use the PagedDataSource, it allows you to turn a standard data source into one that can be paged. Here's an example article

This isn't a way to page the data, but have you looked into the ListView control? It gives the flexibility of repeater / data list but with built in paging like the grid view.
And for paging in sql, you would want to do something like this

This was answered here.

Related

Displaying records in a nice layout

I have a database where I want to display 2 records in a nicely formatted ASP.NET with HTML
Each record would look like this on the web page
The layout would be layers. The data is in a SQL Server 2008 r2 database.
Now whats the best way to get data to populate each record.
Repeater? Or another method?
Regards
Tea
The repeater control is an easy control to use to make sure that your data is displayed the same for all entries in a given data source.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx
This looks like a template and will follow the same html for each entries so it would be better to go for repeater as you will have more control over the html,css and the placemnet part.
yes repeater is best option to use in this situation or you can generate the whole html on you code behind page and assign it to a literal control.

asp.net control for displaying data in a grid

I'm attempting to build a page that displays the same set of information of different "items" in a grid or table. It's akin to a shopping page that displays products in for e.g. a 4 by 3 table.
I came across datagrid and gridview but they display grouped information according to columns and each row representing one item only.
Is there a control that displays data in a very basic grid format instead of tabular form, preferably with built in pagination abilities?
Many thanks in advance
You will want to use a DataList or a Repeater, as those controls allow you to specify the exact HTML you want for each item. Unfortunately, neither of those have built in pagination, but honestly, the built in pagination in the GridView is of questionable usefulness, since it only works if you use a specific data source or load everything from the database up front.
I'm not sure what you mean, you want a basic grid, but gridview doesn't work for you. But in any case, check out the repeater. It will require a bit more work to built a template for your items, but it's very flexible and can handle what you want.

Best UI control to create expandable report in ASP.NET?

I have a SQL Server table full of training course progress. I want to make a report. The report is to be a list of users where each row shows their name, completion status, and percentages. They are to be able to expand each row to show sub-rows which elaborate with section by section detailed stats. What is the best UI control to use in ASP.NET to pair with my SQL data to display this in an easy to read manner?
Dave Ward has a really interesting post on creating a simple data repeater ASP.net page methods and jQuery to display data in a table format. Essentially you will use page methods to send data to the client and format it into a simple table using a micro-template.
As an alternative approach, you could format your data as a html table with the ASP.Net data repeater and use a jQuery plugin to add the paging functionality client side. You may to be careful with this approach, as with a high volume of data your html could become quite large and paging may become important to ensure a quick user experience.
That takes care of your table on the client. To add functionality to expand a row to display detail you can wrap that information in a div tag and attach a click event to show or hide the content.
Sounds like an ASP.NET GridView/ListView combination to make a grouping grid. Check out this blog post for more information: http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html
We have been using Telerik grid controls for similar purpose. They work amazining well.

how to dynamically generate page numbers and only load the corresponding page in the grid?

I need to load data in the gridview dynamically. That is when the user clicks the page number 2 then those records only has to be displayed.. I made a stored proc to return only those records whose page number is sent.. It will also return me the number of records too.. Now i want to create a placeholder which will create the page number buttons dynamically based on the number of records. Could anyone help me with the placeholder code.. ??
You need to use ObjectDataSource for custom paging in GridView.
Check these articles:
https://web.archive.org/web/20210510021915/http://aspnet.4guysfromrolla.com/articles/031506-1.aspx
If you love AJAX, give this a try:
http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx
Quote from the page:
Paging
When working with large tables we
often required to use paging. Although
the DataGrid/GridView has built-in
support for paging they are pretty
much useless. Most developers often
refuse to use the built-in
functionality and use their own custom
logic which usually takes a start
index, page size and other additional
parameters and in turn returns only
the paged records with the total
number of records.
There are enough codes on the page to help you start the balll rolling.
i suggest you to use DataGrid instead. DataGrid has paging property

Why not we use Repeater Control instead of Gridview Control?

I know GridView control comes with lot of built in functionality, which we can achieve from repeater control. GridView control has performance issues. Why don't we use repeater?
You will be thinking why this question, if you can achieve the functionality and performance using repeater use it, but I want to understand why and when we should use repeater and GridView. Can anybody explain me how and when?
GridView supports a tablular style of layout. So works nicely for displaying data that would fit into a table. e.g. report style data
Repeater control is good for a more free style layout. Say for displaying products on an ecommerce website or for displaying entries on a forum or blog.
Like you said, the Repeater can perform certain aspects of the GridView. In this case, you'd want to use a Repeater. However, there are differences between the controls which cannot easily be substituted (or, necessarily, worth the time to implement). You can see a table of differences here. Knowing these differences can make it easier to decide what control to use depending on your needs.
(From Link)
The GridView : it supports paging but
it doesn't provide a flexible layout ,
since its mainly used to display the
data in a table based layout.And If we
looked at data inserting , the
Gridview doesn't have a built in
support for inserting data( since it
doesn't call the insert method of it
underlying data source when you click
on a button with a CommadName set to
"Insert" ).
The Repeater control : you will find
that it provides a flexible layout but
it doesn't support data grouping
,inserting,deleting , updating and
paging through the data .
The GridView is for tabular data only and does a lot of the work for you, like binding data automatically to columns.
The Repeater gives you more control over the result, but you have to do more because nothing gets binded automatically.
I prefer using a Repeater almost every time, but I can see the usefulness of the GridView.

Resources