ASP.NET - bind grid - Asked By msakt on 21-Jun-12 03:46 AM

dataset have 4000 records 

first bind 100 records when click button another 100 records are append in gridview next when i ckick button another 100 records append in grid
bhanupratap singh replied to msakt on 21-Jun-12 03:56 AM
Hi frndz
Just make pagination of gridview
thanks
DL M replied to msakt on 21-Jun-12 04:20 AM
show this code sample.

<script runat="server">

Protected Sub SearchCustomers(ByVal s As Object, ByVal e As EventArgs)

    Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" & _
    "Data Source=H:\Inetpub\wwwroot\code\Customers.mdb")
    Connection.Open()
    Dim Command As New OleDbCommand("Select * FROM tblCustomers", Connection)
    Dim DataReader As OleDbDataReader
    DataReader = Command.ExecuteReader   
    GridView1.DataSource = DataReader
    GridView1.DataBind()
    Connection.Close()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    If Page.IsPostBack = False Then
     GridView1.Visible = False
    Else
     GridView1.Visible = True
   End If
End Sub

</script>
Jitendra Faye replied to msakt on 21-Jun-12 04:40 AM
For your solution check these things-

1. First Check
protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
   {
    //bind your Grid here
   }
}

2. set AllowPaging Property of GridView to True.

3.  Write following code in PageIndexChanging() event of GridView-

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
 GridView1.PageIndex = e.NewPageIndex;
 //bind your Grid here
}


Follow this steps and let me know.

dipa ahuja replied to msakt on 21-Jun-12 07:44 AM
Here is the simple example of gridview paging:
 
Set the AllowPaging = True & pagesize = 100 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
}