This is a migrated thread and some comments may be shown as answers.

Number of Rows Returned (Record Count)

5 Answers 884 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 03 Jul 2008, 04:00 PM
How do I get the number of rows returned displayed in the Grid, either in the  Header or Footer?

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 04 Jul 2008, 07:25 AM
Hi Mike,

There are several ways to do that. The easiest one is to add an aggregate to the bound column like this:
<telerik:GridBoundColumn Aggregate="Count" DataField="ShipName" HeaderText="ShipName" 
   SortExpression="ShipName" UniqueName="ShipName"
</telerik:GridBoundColumn> 

This can also be performed in the code-behind:
GridBoundColumn gBoundColumn = RadGrid1.MasterTableView.GetColumn("myColumn"as GridBoundColumn; 
gBoundColumn.Aggregate = GridAggregateFunction.Count; 

Do not forget to set ShowFooter = true for the grid in order to render footers for its columns.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 04 Jul 2008, 12:43 PM
I definately like the code behind solution better, but I have a couple questions. 

1. Is there a way to put the count in the header and not the footer?

Thank You!
0
Princy
Top achievements
Rank 2
answered on 05 Jul 2008, 05:51 AM
Hi Mike,

Give a try with the following approach and see whether it works.

ASPX:
 <telerik:radgrid id="RadGrid1" runat="server"   ShowFooter="true" Width="500px"  > 
            <MasterTableView  DataSourceID="SqlDataSource1">  
                  <Columns> 
                    <telerik:GridBoundColumn UniqueName="ProductName" Aggregate="Count" DataField="ProductName" HeaderText="ProductName" > 
                    </telerik:GridBoundColumn> 
                </Columns> 
                  
            </MasterTableView> 
        </telerik:radgrid> 

CS:
   string strCount;  
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridFooterItem)  
        {  
            GridFooterItem footer = (GridFooterItem)e.Item;  
            strCount = footer["ProductName"].Text.ToString();  
        }  
          
    }  
    protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridHeaderItem header in RadGrid1.MasterTableView.GetItems(GridItemType.Header))  
        {  
            header["ProductName"].Text = strCount;  
            
        }  
    } 


Thanks
Princy.
0
Accepted
Daniel
Telerik team
answered on 07 Jul 2008, 03:40 PM
Hello Mike,

The above given example should work, but you have to notice that this will override your current column name. It is also possible to simplify this in order to make it more easier and more faster.
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    foreach (GridHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Header)) 
        headerItem["yourColumn"].Text += " " + RadGrid1.MasterTableView.Items.Count.ToString(); 

Kind regards,
Daniel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 07 Jul 2008, 04:23 PM
Thank you Daniel!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mike
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or