Publish Article
Go Freelance

Formatting Grid View - Change appearance of rows


If you are seeing this section and do not see download links, this means that you are not logged into our site. If you already are a member, click on the login link and login into site and come back to this page for downloading the control files. If you are not a member, click on registration link to become a Winista member and download the control for free.

Most of the time our data set has significant number of records and displaying all of the records on one page in GirdView does not give a nice navigation experience to user. That is where Paging feature of GirdView control comes in very handy. What this does is that it allows to set how many records you want to display in one page of the grid and if you have more records than the specified page size, then the control displays a pager which allows you to navigate between pages to see more records.

You can specify the page size by setting PageSize value of the control. But before you do that it is very important that you set AllowPaging property to true. Otherwise the control will not do any paging at all. If you do not specify PageSize property value, then the control uses its default value of 10. Following image shows PropertyView snapshot to show what these properties look like.

By default the pager is displayed at the bottom of the grid. But you can change its placement to Top, Bottom or both places by simply specifying Position property of PagerSettings property. For example to display pager at top and bottom, you will set this property to TopAndBottom. Similarly if you want to control horizontal placement of page number links, you set HorizontalAlign property of PagerStyle. The default alignment if Center.

You can configure the page to show navigation by displaying numeric values for page numbers, which is default. Or you can set Mode property of PagerSetting to one of the following values.

NextPrevious A set of pagination controls consisting of Previous and Next buttons. NextPreviousFirstLast A set of pagination controls consisting of Previous, Next, First, and Last buttons. Numeric A set of pagination controls consisting of numbered link buttons to access pages directly. NumericFirstLast A set of pagination controls consisting of numbered and First and Last link buttons.
  • NextPrevious -
  • NextPreviousFirstLast -
  • Numeric -
  • NumericFirstLast -
    PreviousPageText="Prev" />

Above snippet from ASPX show how these settings look in declarative mode. You will notice that I have specified some values for properties like FirstPageText, LastPageText, NextPageText. These values decide what text to show for indicating Next, Previous and Last page. Default value for these properties is set to angle bracket signs (<, >, <<, >>).

Setting Page Size From Codebehind

So far I have been talking about how to set various property values at design time or on ASPX page. There are times when you have to configure the appearance of the grid view pager based on some conditions or data value only known at run time. For those times you can take help from code behind and specify the values in the implementation code itself. For example the following code from the attached project shows the page size of the grid view is changed based on the value user specifies in the text box.

protected void OnChangePageSize(Object sender, EventArgs e)
	Int32 iPageSize = ctlGridView.PageSize;
	if (Int32.TryParse(ctlPageSize.Text, out iPageSize))
    	ctlGridView.PageSize = iPageSize;

There is lot more you can do with pager settings and other property values. In our next article show you some of the advanced paging techniques.

Go Freelance
Home     About us     Contact us    Copyright    Privacy Policy    Return Policy    Advertisers
Copyright © Netomatix