ASP.NET - Bind Gridview - Asked By msakt on 18-May-12 12:29 AM

i have 5000 record in table..its bind to gridview have more time..so i want first 500 record bind,when scroll down next 500 record bind..withou use paging

how?
[)ia6l0 iii replied to msakt on 18-May-12 12:47 AM
Do you even think the user will manage to read through all 500 at one shot? If yes, then a download report of the gridview rows is a better solution.

If possible, use the jQuery's Lazy Load plugin and load the html dynamically using jSon. I have not worked on this before, but you should find good set of examples on the internet. 
Somesh Yadav replied to msakt on 18-May-12 01:02 AM
try this,
http://msdn.microsoft.com/en-us/library/fkx0cy6d.aspx
Chintan Vaghela replied to msakt on 18-May-12 02:31 AM

Hello,

 

Use TOP function in SQL query to BIND GridView

 

Make your query to check top records as following way

 

cmd.CommandType = CommandType.Text;

      cmd.CommandText = "select Top " + PageSize + " id,name tablename where id not in (select top (" + PageSize * number + ") id from tablename)";

      cmd.Connection = con;

Take two button next and previous to increment/decrement number

switch (e.CommandName)

      {

        case "Previous":

          if (CurrentPage != 0)

          {

            CurrentPage = CurrentPage - 1;

            lblCurrentPage.Text = CurrentPage.ToString();

          }

        

          break;

 

        case "Next":

          if (GridView2.Rows.Count != 0)

          {

            CurrentPage = CurrentPage + 1;

            lblCurrentPage.Text = CurrentPage.ToString();

          }

         

          break;

      }

 

 

 

 

Hope this helpful!

 

Happy Coding J

Thanks

 

 

 

 

dipa ahuja replied to msakt on 20-May-12 03:23 PM
Here is the simple example of gridview paging:
 
Set the AllowPaging = True for gridview and write this code in codebehind
 
protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
     bindGrid();
   }
}
void bindGrid()
{
   SqlDataAdapter da = new SqlDataAdapter("select * from TableName", "Connection String");
   DataTable dt = new DataTable();   
  da.Fill(dt);
   GridView1.DataSource = dt;
   GridView1.DataBind();
}
 
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   GridView1.PageIndex = e.NewPageIndex;
   BindGrid();
   //Bind Grid
}