Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging in Gridview not working 2nd page data not showing data?

my gridview

<div style="margin-left: 280px">
   <asp:GridView ID="exportGrdVw" runat="server" BackColor="White"  
        AllowPaging="True" PageSize="3" 
        OnPageIndexChanging="exportGrdVw_PageIndexChanging" 
        onpageindexchanged="exportGrdVw_PageIndexChanged">
   </asp:GridView>
</div>

my code

SqlConnection con = new SqlConnection("server=acer-Pc\\Sql;database=MYDB;trusted_connection=yes");  
//DataSet ds = new DataSet();
DataTable table = new DataTable();    
protected void Page_Load(object sender, EventArgs e)
{        
    if (!IsPostBack)
    {
        SqlDataAdapter da = new SqlDataAdapter("select customername,contactno,address from employee ", con);
        da.Fill(table);
        BindEmployee();
    }
 }
 public void BindEmployee()
 {
    exportGrdVw.DataSource = table;
    exportGrdVw.DataBind();
 }
 protected void exportGrdVw_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
    exportGrdVw.PageIndex = e.NewPageIndex;
    BindEmployee();
 }

the problem is gridview is displaying but when i click page 2. 2nd page data is not showing (blank). pls help me to solve this problem. see that the code is correct or not

like image 975
user2207817 Avatar asked Mar 27 '13 18:03

user2207817


People also ask

What is paging in GridView?

The paging feature can be used with any data source object that supports the System. Collections. ICollection interface or a data source that supports paging capability. To enable the paging feature, set the AllowPaging property to true . By default, the GridView control displays 10 records on a page at a time.

What is pagination in asp net?

This is what custom paging is all about i.e. fetching only required data from database. To enable Custom paging we need to explicitly set AllowCustomPaging property of DataGrid control to True. Use PageSize property to set the number of records to be displayed per page.


1 Answers

Use like below

SqlConnection con = new SqlConnection("server=acer-Pc\\Sql;database=MYDB;trusted_connection=yes");
//DataSet ds = new DataSet();
DataTable table = new DataTable();    
protected void Page_Load(object sender, EventArgs e)
{        
   if (!IsPostBack)
   {              
       BindEmployee();
   }
}
public void BindEmployee()
{
    SqlDataAdapter da = new SqlDataAdapter("select customername,contactno,address from employee ", con);
    da.Fill(table);
    exportGrdVw.DataSource = table;
    exportGrdVw.DataBind();
}
protected void exportGrdVw_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    exportGrdVw.PageIndex = e.NewPageIndex;
    BindEmployee();
}
like image 154
शेखर Avatar answered Nov 24 '22 04:11

शेखर