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
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