Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using repeater to display records in a page from sql database, I want to display total number of records i am fetching from database on a label at the top of repeater. So that user can see he has this number of records. Below is my code to bind repeater data.
C#
protected void BindRepeaterData()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("sps_searchresult", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@country", 1);
        cmd.Parameters.AddWithValue("@state", state);
        cmd.Parameters.AddWithValue("@pincode", pincode);
        cmd.Parameters.AddWithValue("@category", category);
        cmd.Parameters.AddWithValue("@subcategory", subcategory);
        con.Close();
        
        //save the result in data table
        DataTable dt = new DataTable();
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        adp.Fill(dt);
        PagedDataSource pgitems = new PagedDataSource();
        DataView dv = new DataView(dt);
        pgitems.DataSource = dv;
        pgitems.AllowPaging = true;
        pgitems.PageSize = 5;
        pgitems.CurrentPageIndex = PageNumber;
        if (pgitems.PageCount > 1)
        {
            rptPaging.Visible = true;
            ArrayList pages = new ArrayList();
            for (int i = 0; i < pgitems.PageCount; i++)
                pages.Add((i + 1).ToString());
            rptPaging.DataSource = pages;
            rptPaging.DataBind();
        }
        else
        {
            rptPaging.Visible = false;
        }
        rep_results.DataSource = pgitems;
        rep_results.DataBind();

        //Change the text Now viewing text
        lblCurrentPage.Text = "Page : " + (PageNumber + 1).ToString() + " of " + pgitems.PageCount.ToString();
    }
Posted

1 solution

You can get the count from DataTable itself by...
C#
int noOfRows = dt.Rows.Count;
 
Share this answer
 
v2
Comments
Raj Negi 14-May-14 5:47am    
thats what i m looking for...thanks
Welcome Raj. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900