Hey Guys,
I have a details view bounded with a sqldatasource.
I want to calculate the the total no of entries in details view and show it to the user. Please tell me how to do this??

Try this code
Default.aspx.cs

protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        // Get the pager row.
        DetailsViewRow pagerRow = DetailsView1 .BottomPagerRow;

        // Get the Label controls that display the current page information 
        // from the pager row.
        Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
        Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");

        if ((pageNum != null) && (totalNum != null))
        {
            // Update the Label controls with the current page values.
            int page = DetailsView1 .DataItemIndex + 1;
            int count = DetailsView1 .DataItemCount;

            pageNum.Text = page.ToString();
            totalNum.Text = count.ToString();
        }
}

Default.aspx

<form id="form1" runat="server">
    <div>
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
            DataKeyNames="CategoryID" DataSourceID="SqlDataSource1" Height="50px" Style="z-index: 100;
            left: 195px; position: absolute; top: 225px" Width="125px" OnDataBound="DetailsView1_DataBound" OnPageIndexChanging="DetailsView1_PageIndexChanging">
            
            <Fields>
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                    ReadOnly="True" SortExpression="CategoryID" />
                <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            </Fields>

//Note This Part



            <PagerTemplate>
                Page <asp:Label id="PageNumberLabel" runat="server" /> 
                  of <asp:Label id="TotalPagesLabel" runat="server" />   
            </PagerTemplate>



        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
             SelectCommand="SELECT * FROM [Categories]" OnSelected="SqlDataSource1_Selected">
        </asp:SqlDataSource>
        
      
    
    </div>
    </form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.