Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 27th, 2009, 09:14 AM
Authorized User
 
Join Date: Apr 2007
Location: Delhi, Delhi, India.
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Paging

Hello Friends,
I'm creating custom paging. Everything is working fine but there is a problem actually
i'm displaying for four pages at a time i.e. 1,2,3,4 and a Next for moving on Next pages.
But as i click on Next button it's bringing correct records and correct paging control.
But now if i click on any New page buttons that's n't working i have to press page button
two times to work on.
for example if i've to view Page No. 6 then i've to press Page No. 6 two times

http://autoneed.in/Rough/Paging.aspx
  #2 (permalink)  
Old August 27th, 2009, 10:33 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Impossible to tell by just looking at the screen, but is it possible you aren't rebinding the GridView in the postback?
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #3 (permalink)  
Old August 28th, 2009, 05:23 AM
Authorized User
 
Join Date: Apr 2007
Location: Delhi, Delhi, India.
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Paging

Hello sir, here i'm giving my code............


protected void Page_Load(object sender, EventArgs e)
{
//Keep at top because it specifies the total no. of records available in the table

if (!Page.IsPostBack)
{
//Current Page No.
ViewState["Current_PNo"] = 1;

//State Page No.
ViewState["Current_Start"] = 1;

//Last Page No.
ViewState["Current_Last"] = 4;
//lblMsg.Text = ViewState["Current_Start"].ToString() + "," + ViewState["Current_Last"].ToString();

//Set MaxRow
ViewState["MaxRow"] = 10;

//startNo and maxNo
bindDataList(1, int.Parse(ViewState["MaxRow"].ToString()));
//Creates the paging nos i.e. 1,2,3,4
createPagingControl(int.Parse(ViewState["Current_Start"].ToString()),int.Parse(ViewState["Current_Last"].ToString()));

}
else
{
int start = Convert.ToInt32(ViewState["Current_Start"].ToString());
int last= Convert.ToInt32(ViewState["Current_Last"].ToString());
createPagingControl(start,last);
}

}

public void bindDataList(int startRow,int maxRow)
{
using (SqlConnection mCon = new SqlConnection(ConfigurationManager.ConnectionStrin gs["ConnectionString"].ToString()))
{
int maxRow_New = startRow + maxRow;
Session["MaxRow"] = maxRow_New.ToString();
//string strsql = "Select * From Table2 Where Active=1 and ID>="+startRow+" and ID<="+maxRow_New+" ";
string strsql = null;
strsql="Select *,Total=(Select Count(*) From Table2 Where Active=1) "+
"From Table2 Where Active=1 and ID>="+startRow+" and ID<="+maxRow+" ";

SqlCommand mDataCom = new SqlCommand();
mDataCom.Connection = mCon;
mDataCom.CommandText = strsql;
mDataCom.CommandType = CommandType.Text;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(mDataCom);
da.Fill(ds);
PagedDataSource page = new PagedDataSource();
page.AllowPaging = true;

//Set Total No. of Rows in the Database
ViewState["RowCount"] = ds.Tables[0].Rows[0]["Total"].ToString();

//Set maxRow
page.PageSize = int.Parse(ViewState["MaxRow"].ToString());
page.DataSource = ds.Tables[0].DefaultView;

//DataList1.DataSource = ds.Tables[0];
DataList1.DataSource = page;
DataList1.DataBind();
}
}
public void createPagingControl(int start,int last)
{
int rowCount = Convert.ToInt32(ViewState["RowCount"].ToString());
PlaceHolder1.Controls.Clear();
if (rowCount / int.Parse(ViewState["MaxRow"].ToString()) >= last)
{
for (int i = start; i <= last; i++)
{
LinkButton lnk = new LinkButton();
lnk.Text = i.ToString();
lnk.ToolTip = i.ToString() + ", Paging No.";
lnk.Click += new EventHandler(lnk_Click);
Label lbl = new Label();
lbl.Text = " ";
PlaceHolder1.Controls.Add(lnk);
PlaceHolder1.Controls.Add(lbl);
lnk.Style["text-decoration"] = "underline";
lnk.Style["Color"] = "DarkBlue";
lnk.Enabled = true;
}
}
}

public void lnk_Click(object sender, EventArgs e)
{
LinkButton lnk= sender as LinkButton;

lnk.Style["text-decoration"] = "none";
lnk.Style["Color"] = "Maroon";
lnk.Enabled = false;
int currentPage = int.Parse(lnk.Text);

//Multiply by maxRow
int maxRow = currentPage * int.Parse(ViewState["MaxRow"].ToString());
int startRow = currentPage == 1 ? 1 : maxRow - (int.Parse(ViewState["MaxRow"].ToString())-1);
bindDataList(startRow, maxRow);
}
public void lnkClick(int cureentPage)
{
//LinkButton lnk = sender as LinkButton;
LinkButton lnk = new LinkButton();
lnk.Text = cureentPage.ToString();
lnk.Style["text-decoration"] = "none";
lnk.Style["Color"] = "Maroon";
lnk.Enabled = false;
int currentPage = int.Parse(lnk.Text);
//Multiply by maxRow
int maxRow = currentPage * int.Parse(ViewState["MaxRow"].ToString());
int startRow = currentPage == 1 ? 1 : maxRow - (int.Parse(ViewState["MaxRow"].ToString()) - 1);
bindDataList(startRow, maxRow);
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int start= Convert.ToInt32(ViewState["Current_Last"].ToString())+1;
int last = Convert.ToInt32(ViewState["Current_Last"].ToString()) + 4;
ViewState["Current_Start"] = start.ToString();
ViewState["Current_Last"] = last.ToString();
lblMsg.Text = ViewState["Current_Start"].ToString() + "," + ViewState["Current_Last"].ToString();
int currentPage = int.Parse(ViewState["Current_Start"].ToString());
ViewState["Empty"] = start.ToString();
lnkClick(currentPage);
createPagingControl(start,last);
//lblMsg.Text = "Next Clicked";
}


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom paging and sorting? asptwodev BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 September 22nd, 2007 02:06 AM
Chp.12 'custom' SqlDataSource and paging studen77 BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 8 April 4th, 2007 05:49 PM
Custom Paging with limited no. of numeric links!!! kudzuconf ASP.NET 1.0 and 1.1 Basics 1 March 29th, 2007 01:50 AM
Custom Paging with Limited numeric links kudzuconf ASP.NET 1.x and 2.0 Application Design 0 October 13th, 2006 03:04 PM
Objectdatasource, Custom Paging, and Filtering crimsondr ASP.NET 2.0 Professional 0 December 23rd, 2005 12:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.