Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I just retrieved the data from database and displayed it in a div.Now i want to apply paging for this.Kindly tell me how to do that.I used the following coding.
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select Departure from Flight_Info";
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{


Response.Write(@"<div align='center'><font color='red'>" + dr.GetValue(0) + "</font></div>");
}
con.Close();
}
Posted

Assuming you have a lot of info to display (and there is no reason for paging otherwise) can I suggest that you use a GridView instead of just loading it into a bunch of divisions?

If you do, you can use the built in paging of a GridView: Showing a page of information at a time in a GridView[^]

If you don't then you have to maintain a Session variable which tells you which record to start with, and kip as appropraite, display next and prev buttons yourself, etc.

Displaying in a GridView is neater - and a lot easier when you want to display more than one item of information for each record later, too.
 
Share this answer
 
Use Session to manitanin the page size limit dynamically .
 
Share this answer
 
use datagrid for paging it is easy rather than div
 
Share this answer
 
 
Share this answer
 

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