Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am doing custom paging in my project. But the record count is around 1500. And i am displaying 10 records per page. So there are total of 150 pages. So I am displaying as below.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25...150


--> ... and 150 is disabled

this I have done and I am able to view up util 25 pages only :( now I want to handle the situation as below

Question ==> I want to click on ... so that it displays as below

1...26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50...150


And when I click on ... after 50 it should display as

1...51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75...150



Kindly Help me

--------------------------------code(.cs)--------------------------------------------------
protected void ddlhub_SelectedIndexChanged(object sender, EventArgs e)
{

    intRoleId = Convert.ToInt32(Session[TMS.Common.CommonConstants.CONST_ROLE_ID]);

    BindGrid(0, GridZeroApprovedKm.PageSize);
    gridcolumninvisible();


}



protected void BindGrid(int pageindex, int pagesize)
{
    string Modified_by = Session[TMS.Common.CommonConstants.CONST_USER_ID].ToString();
    TMSDatabase TMSDb = TMSDatabase.CreateInstance();
    string ConnectionString = TMSDb.ConnectionString.ToString();
    SqlConnection con = new SqlConnection(ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("APPROVED_KM", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add(new SqlParameter("@HUB_ID", SqlDbType.Int));
    cmd.Parameters.Add(new SqlParameter("@Pageindex", SqlDbType.Int));
    cmd.Parameters.Add(new SqlParameter("@pageSize", SqlDbType.Int));
    cmd.Parameters.Add(new SqlParameter("@totalrows", SqlDbType.Int));
    cmd.Parameters.Add(new SqlParameter("@Modified_by", SqlDbType.VarChar));


    cmd.Parameters["@totalrows"].Direction = ParameterDirection.Output;
    cmd.Parameters["@HUB_ID"].Value = ddlhub.SelectedValue;
    cmd.Parameters["@Pageindex"].Value = pageindex;
    cmd.Parameters["@pageSize"].Value = pagesize;
    cmd.Parameters["@Modified_by"].Value = Modified_by;



    IDataReader idr = cmd.ExecuteReader();
    GridZeroApprovedKm.DataSource = idr;
    GridZeroApprovedKm.DataBind();

    if (GridZeroApprovedKm.Rows.Count == 0)
    {

        msgLabel.Text = "No records found for the selected search criteria.";
        msgLabel.Visible = true;
        return;
    }
    else
    {
        msgLabel.Text = "";
    }
    MsgUpdatePanel.Update();

    gridcolumninvisible();
    idr.Close();
    con.Close();

    int recordcount = Convert.ToInt32(cmd.Parameters["@totalrows"].Value);
    if (pageindex == 0)
    {
        this.RepeaterBind(0, GridZeroApprovedKm.PageSize, recordcount);
    }
    else
    {
        this.RepeaterBind(pageindex, GridZeroApprovedKm.PageSize, recordcount);
    }
}


protected void RepeaterBind(int pageindex, int pagesize, int totalrows)
{

    int totalpages = totalrows / pagesize;

    if ((totalrows % pagesize) != 0)
    {

        totalpages += 1;

    }
    List<ListItem> pages = new List<ListItem>();


    if (totalpages > 1)
    {

        for (int i = 1; i <= totalpages; i++)
        {
            if (i <= 25)
            {
                pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
            }
            else
            {
                pages.Add(new ListItem("...", "...", false));
                pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), false));
                break;
            }
        }

    }
    RepeaterForPaging.DataSource = pages;
    RepeaterForPaging.DataBind();
}

protected void Page_Changed_click(object sender, EventArgs e)
{


    //int totalrows = 0;

    int pageindex = int.Parse((sender as LinkButton).CommandArgument);

    pageindex = pageindex - 1;

    GridZeroApprovedKm.PageIndex = pageindex;

    BindGrid(pageindex, GridZeroApprovedKm.PageSize);

}


//// i am handling in RepeaterBind function the display of 25 pages....
Posted
Updated 14-Dec-13 5:18am
v6
Comments
ZurdoDev 13-Dec-13 13:56pm    
Where are you stuck?
anurag19289 14-Dec-13 3:01am    
i have updated the code..
ZurdoDev 14-Dec-13 11:12am    
You need to post the relevant code and show where you are stuck. It is unlikely anyone will look through hundreds of lines of code to figure it out when you could just debug it and find the issue.
anurag19289 14-Dec-13 11:14am    
you are right... let me update the question
anurag19289 14-Dec-13 11:21am    
RyanDev, I have updated the question...

1)ddlhub_SelectedIndexChanged --> on selcection of dropdown the grid will be populated
BindGrid(0, GridZeroApprovedKm.PageSize);

2) this.RepeaterBind(pageindex, GridZeroApprovedKm.PageSize, recordcount);
this gets me the page number....

3)
for (int i = 1; i <= totalpages; i++)
{
if (i <= 25)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
else
{
pages.Add(new ListItem("...", "...", false));
pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), false));
break;
}
}

-- i m stuck here...as i am displaying only 25 pages.

You need to do changes in your code based clicked page no. Check this article
Pager Control for ASP.NET[^]

jQuery pagination plugins[^]
 
Share this answer
 
I have solved it in this way. Though it looks bit clumsy but some how it solved the problem.

C#
protected void RepeaterBind(int pageindex, int pagesize, int totalrows)
        {
            int j=1;
            int k = 1;
            int l;
            int mod;

            mod = (pageindex / 25);

            int totalpages = totalrows / pagesize;

            if ((totalrows % pagesize) != 0)
            {

                totalpages += 1;

            }
            List<ListItem> pages = new List<ListItem>();


            if (totalpages > 1)
            {

                if (pageindex == 0)
                {

                    for (int i = k; i <= 26; i++)
                    {

                        if (i <= 25)
                        {
                            pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
                        }
                        else
                        {
                            pages.Add(new ListItem("...", (i).ToString(), true));
                            pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
                            break;
                        }
                    }

                }

                if (mod != 0 && pageindex!=0)
                {
                    pages.Add(new ListItem(j.ToString(), j.ToString(), true));
                    pages.Add(new ListItem("...", (mod*25).ToString(), true));

                    l = (totalpages / 25)-(pageindex / 25);

                    if (l >= 2 )
                    {
                        for (int i = ((25 * (mod)) + 1); i <= (((25 * (mod)) + 1) + 25); i++)
                        {

                            if (i <= (((25 * (mod)) + 1) + 24))
                            {
                                pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
                            }
                            else
                            {
                                pages.Add(new ListItem("...", (i).ToString(), true));
                                pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
                                break;
                            }

                        }
                    }
                    else
                    {
                        if (l == 1 && ((pageindex % 5) == 4))
                        {

                            for (int i = ((25 * (mod)) + 1); i <= (((25 * (mod)) + 1) + 25); i++)
                            {

                                if (i <= (((25 * (mod)) + 1) + 24))
                                {
                                    pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
                                }
                                else
                                {
                                    pages.Add(new ListItem("...", (i).ToString(), true));
                                    pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
                                    break;
                                }

                            }
                        }
                        else
                        {
                            for (int i = ((25 * (mod)) + 1); i <= totalpages; i++)
                            {

                                pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));

                            }
                        }

                    }

                }
                else if (mod == 0 && pageindex != 0)
                {

                    for (int i = k; i <= 26; i++)
                    {

                        if (i <= 25)
                        {
                            pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
                        }
                        else
                        {
                            pages.Add(new ListItem("...", (i).ToString(), true));
                            pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
                            break;
                        }
                    }

                }
            }

            RepeaterForPaging.DataSource = pages;
            RepeaterForPaging.DataBind();
        }
 
Share this answer
 
v2

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