<script runat="Server">
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
totalRows.Text = e.AffectedRows.ToString();
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" AllowPaging="True">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=(local);Initial Catalog=Northwind;user id=sa;password=123456;"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]" OnSelected="SqlDataSource1_Selected">
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="Number of total rows:"></asp:Label>
<asp:Label ID="totalRows" runat="server" Text="Label"></asp:Label>