Showing x to y of z records

M

Mike Chamberlain

Hi.

I'm extending the built in DataGrid to show a summary above the header
row (see subject). I am doing this by creating a new ListItemType.Item
above the header row.


Showing x to y of z records
----------------------------------
| header | header | header |
|--------------------------------|
| data | data | data |
| data | data | data |
| data | data | data |
| data | data | data |
----------------------------------
| Page 1 2 3 4 5 |
----------------------------------

x and y are displaying correctly, but z is always zero. I assume this
is because I am using the ItemCreated event, at which point the data is
not bound, so Items.Count is still zero. Can anyone suggest a way to
modify the code below to show z correctly?


private void ExtDataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
{
// add summary text to appear before grid
if(ShowPagingSummary && e.Item.ItemType == ListItemType.Header)
{
TableCellCollection cells = e.Item.Cells;
Label lb = new Label();
int firstRecord = this.PageSize * (this.CurrentPageIndex) + 1;
int lastRecord = firstRecord + this.PageSize - 1;
lb.Text = String.Format("Showing {0} to {1} of {2} records",
firstRecord, lastRecord, this.Items.Count);

TableCell cell = new TableCell();
cell.CssClass = "gridPagingSummary";
cell.Controls.Add(lb);
cell.ColumnSpan = cells.Count;

DataGridItem summary = new DataGridItem(0, 0, ListItemType.Item);
summary.Cells.Add(cell);
summary.Visible = true;

this.Controls[0].Controls.Add(summary);

}
}

Thanks in advance for your help,

Mike
 
J

justcome

define a page level variable to hold the rows count of the
data table which is bound with your grid. then use it
instead of 'this.Items.Count' in your code. that's it.
-----Original Message-----
Hi.

I'm extending the built in DataGrid to show a summary above the header
row (see subject). I am doing this by creating a new ListItemType.Item
above the header row.


Showing x to y of z records
----------------------------------
| header | header | header |
|--------------------------------|
| data | data | data |
| data | data | data |
| data | data | data |
| data | data | data |
----------------------------------
| Page 1 2 3 4 5 |
----------------------------------

x and y are displaying correctly, but z is always zero. I assume this
is because I am using the ItemCreated event, at which point the data is
not bound, so Items.Count is still zero. Can anyone suggest a way to
modify the code below to show z correctly?


private void ExtDataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
{
// add summary text to appear before grid
if(ShowPagingSummary && e.Item.ItemType == ListItemType.Header)
{
TableCellCollection cells = e.Item.Cells;
Label lb = new Label();
int firstRecord = this.PageSize * (this.CurrentPageIndex) + 1;
int lastRecord = firstRecord + this.PageSize - 1;
lb.Text = String.Format("Showing {0} to {1} of {2} records",
firstRecord, lastRecord, this.Items.Count);

TableCell cell = new TableCell();
cell.CssClass = "gridPagingSummary";
cell.Controls.Add(lb);
cell.ColumnSpan = cells.Count;

DataGridItem summary = new DataGridItem(0, 0, ListItemType.Item);
summary.Cells.Add(cell);
summary.Visible = true;

this.Controls[0].Controls.Add(summary);

}
}

Thanks in advance for your help,

Mike
.
 
M

Mike Chamberlain

I don't want the code in my extended datagrid to depend on the code on
the page, ie. I want it completely self contained. Is this possible?

Mike
define a page level variable to hold the rows count of the
data table which is bound with your grid. then use it
instead of 'this.Items.Count' in your code. that's it.

-----Original Message-----
Hi.

I'm extending the built in DataGrid to show a summary

above the header
row (see subject). I am doing this by creating a new
ListItemType.Item

above the header row.


Showing x to y of z records
----------------------------------
| header | header | header |
|--------------------------------|
| data | data | data |
| data | data | data |
| data | data | data |
| data | data | data |

I assume this
is because I am using the ItemCreated event, at which

point the data is
not bound, so Items.Count is still zero. Can anyone

suggest a way to
modify the code below to show z correctly?


private void ExtDataGrid_ItemCreated(object sender,

DataGridItemEventArgs e)
{
// add summary text to appear before grid
if(ShowPagingSummary && e.Item.ItemType ==
ListItemType.Header)

{
TableCellCollection cells = e.Item.Cells;
Label lb = new Label();


int firstRecord = this.PageSize *

(this.CurrentPageIndex) + 1;
int lastRecord = firstRecord +

this.PageSize - 1;
lb.Text = String.Format("Showing {0} to

{1} of {2} records",
firstRecord, lastRecord, this.Items.Count);

TableCell cell = new TableCell();
cell.CssClass = "gridPagingSummary";
cell.Controls.Add(lb);
cell.ColumnSpan = cells.Count;

DataGridItem summary = new DataGridItem(0,

0, ListItemType.Item);
summary.Cells.Add(cell);
summary.Visible = true;

this.Controls[0].Controls.Add(summary);

}
}

Thanks in advance for your help,

Mike
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top