Re: row count in inherited GridView control
- From: "J055" <j055@xxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 16:29:08 +0100
Hi
I've found a solution which works for me now. The answer was sitting in the
GridView.InitializePager method all along. If you want to get the total
number (count) of rows in your data source for use in your GridView pager
row then you use the pagedDataSource.DataSourceCount property.
I've created a derived GridView which contains added page information by
overriding the InitializePager method. Here's the code for anyone who wants
to do something similar.
protected override void InitializePager(GridViewRow row, int columnSpan,
PagedDataSource pagedDataSource)
{
// call the base method first
base.InitializePager(row, columnSpan, pagedDataSource);
// create a new tablecell to contain the new page information
TableCell cell1 = new TableCell();
// divide the pager row in half
int ltSpan = (int)(columnSpan / 2);
int rtSpan = columnSpan - ltSpan;
row.Cells[0].ColumnSpan = rtSpan;
// add the new label control with the new page info
cell1.Controls.Add(PageInfo(pagedDataSource.DataSourceCount));
// add the new cell to the page row and make some adjustments
row.Controls.AddAt(0, cell1);
row.Cells[0].ColumnSpan = ltSpan;
row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
}
protected Label PageInfo(int rowCount)
{
Label label1 = new Label();
int currentPageFirstRow = ((PageIndex * PageSize) + 1);
int currentPageLastRow = 0;
int lastPageRemainder = (rowCount % PageSize);
// if you're on the last page the currentPageLastRow
// may be different to the other pages
currentPageLastRow = (PageCount == (PageIndex + 1) ?
(currentPageFirstRow + lastPageRemainder - 1) : (currentPageFirstRow +
PageSize - 1));
label1.Text = String.Format("Records {0} to {1} of {2}",
currentPageFirstRow, currentPageLastRow, rowCount);
return label1;
}
Some of the formatting will probably need improving to make it look nice but
hopefully this provides a good start.
Cheers
Andrew
.
- References:
- row count in inherited GridView control
- From: J055
- RE: row count in inherited GridView control
- From: Steven Cheng[MSFT]
- Re: row count in inherited GridView control
- From: J055
- Re: row count in inherited GridView control
- From: J055
- row count in inherited GridView control
- Prev by Date: Re: row count in inherited GridView control
- Next by Date: error using .NET CrystalReportViewer (.NET 1.1 VS.NET 2003)
- Previous by thread: Re: row count in inherited GridView control
- Next by thread: Image Server Control's Style/Border
- Index(es):
Relevant Pages
|