|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Showing x to y of z recordsI'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 | x and y are displaying correctly, but z is always zero. I assume this |--------------------------------| | data | data | data | | data | data | data | | data | data | data | | data | data | data | ---------------------------------- | Page 1 2 3 4 5 | ---------------------------------- 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 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----- above the header >Hi. > >I'm extending the built in DataGrid to show a summary Show quoteHide quote >row (see subject). I am doing this by creating a new I assume this 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. >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? (this.CurrentPageIndex) + 1;> > >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 * > int lastRecord = firstRecord + this.PageSize - 1;> lb.Text = String.Format("Showing {0} to {1} of {2} records",> firstRecord, lastRecord, this.Items.Count); 0, ListItemType.Item);> > TableCell cell = new TableCell(); > cell.CssClass = "gridPagingSummary"; > cell.Controls.Add(lb); > cell.ColumnSpan = cells.Count; > > DataGridItem summary = new DataGridItem(0, Show quoteHide quote > summary.Cells.Add(cell); > summary.Visible = true; > > this.Controls[0].Controls.Add(summary); > > } >} > >Thanks in advance for your help, > >Mike >. > 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 >>. >>
Searched Datagrid with Paging?
Using Server.Transfer with HyperLinkColumn in a datagrid 5th Re-Post with NO RESPONSE FROM MS! Questions concerning detailsview or datagrid ASP.NET 2.0 How to capture CheckChanged event from Radiobutton in Datagrid? radiobutton and datagrid Handling events for Checkbox in Data Grid search function on different page selected Fonction de recherche dans un datagrid Make links different color in the datagrid |
|||||||||||||||||||||||