Home All Groups Group Topic Archive Search About
Author
15 Mar 2005 5:58 AM
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

Author
16 Mar 2005 8:20 PM
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
Show quoteHide quote
>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);
Show quoteHide quote
>        summary.Cells.Add(cell);
>        summary.Visible = true;
>
>        this.Controls[0].Controls.Add(summary);
>           
>    }
>}
>
>Thanks in advance for your help,
>
>Mike
>.
>
Author
17 Mar 2005 5:24 AM
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

justcome wrote:
Show quoteHide quote
> 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
>>.
>>