Get the value of SelectCountMethod

Hi All,

Does anyone know how to get the value of the SelectCountMethod in an ObjectDataSource and add it to the header of a GridView and a textbox?  I am using a BLL, DAL, C#.   There is some  sample code.  Any help would be greatly appreciated.

Jus


The code from the DAL is:

SELECT COUNT(*)
FROM phone_Makes
=========================================================
The code from the BLL is:

    public int TotalNumberOfMakes()
    {
        return Adapter.TotalNumberOfMakes().GetValueOrDefault();
    }
==========================================================
The code from the ObjectDataSoure:

        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetMakesPagesAndSorted" 
            TypeName="MakesBLL" 
            EnablePaging="True" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCountMethod="TotalNumberOfMakes" 
            SortParameterName="sortExpression">
            <SelectParameters>
            </SelectParameters>            
        </asp:ObjectDataSource>

Open in new window

Justice75Asked:
Who is Participating?
 
RameshSConnect With a Mentor Commented:
You are setting the TotalNumberOfMakes() method as SelectCountMethod to the ObjectDataSource. ObjectDataSource uses this method to retrieve a row count internally. So you can use the same method to retrive the row  count. To display this value in the GridView header and a textbox


MakesBLL bll = new MakesBLL(); 
int rowCount = bll.TotalNumberOfMakes();
GridView1.Columns[2].HeaderText = "Total : "  + rowCount.ToString();
TextBox1.Text = = rowCount.ToString();

Open in new window

0
 
Justice75Author Commented:
Ramesh,

Thank you for your response.  Should that be in the GridView1_Load method or some other one?  Thank you.. This worked perfect.

Jus
0
 
Justice75Author Commented:
Clear, concise and straight to the point!
0
 
Justice75Author Commented:
Also, When I added it to the Columns[2] it replaced the header text for that column.  Is there any way that it can go on the row with the paging mechanism?

Jus
0
All Courses

From novice to tech pro — start learning today.