views:

1113

answers:

2
+3  A: 

The ObjectDataSource does not have a direct way to get the total row count. One of the reasons for this is that if all you want is the total row count then you don't need the data source at all! To get the row count just talk to your Business Logic Layer (BLL) and get the total rows:

MyBLL bll = new MyBLL();
int customerRowCount = bll.Customers.GetRowCount();

The ObjectDataSource does have a SelectCountMethod that can be used when data bound controls such as the GridView need to access the total row count. However, this is only used while also performing a Select operation. That is, there is no way to only get the row count. The row count is only used so that the data bound control can display a pager control - it is not used for anything else.

Eilon
A: 

You can achieve this very simply using a pager template e.g.

       <asp:DataPager PagedControlID="PagedControlId" PageSize="20" QueryStringField="QueryStringName" ID="InfoPager" runat="server">
           <Fields>
               <asp:TemplatePagerField>
                   <PagerTemplate>
                        Showing results 
                        <%=InfoPager.StartRowIndex + 1 %> 
                        to 
                        <%= (new []{(InfoPager.StartRowIndex + InfoPager.PageSize),InfoPager.TotalRowCount})
                                      .OrderBy(x => x)
                                      .First()%> 
                        of 
                        <%=InfoPager.TotalRowCount %>
                   </PagerTemplate>
               </asp:TemplatePagerField>
           </Fields>
       </asp:DataPager>

This will produce the text "Results x to y of z" including a check for the last page.

Cheers,

Ed

Ed Bishop