i had used gridview to display records from database, i am able to display records but in pagination when i click 2,3,4,5......10 page the gridview disappears.

find the code below for gridview:

<asp:GridView ID="GridView1"   runat="server"  AllowPaging="True" PageSize="10"   AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" onselectedindexchanged="GridView1_SelectedIndexChanged"
        GridLines="Horizontal">

code behind:

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.BottomPagerRow.Visible = true;
       
        GridView1.PageIndex = e.NewPageIndex;
      
        GridView1.DataBind();
        
        
    }

where are you setting the gridview's datasource?

in button click i wrote dataource. i need to select date from date picker and using button click then display it in gridview.

finally it worked for me:) i got it..

sorry for not posting full code..

find the below code

protected void bindgrid()
    {

if (BasicDatePicker1.SelectedDate <= DateTime.Now)
        {

            Session["sesdb"] = null;
           

            DateTime from = this.BasicDatePicker1.SelectedDate;
         

            string strSql = "query";

            DataTable dt = new DataTable();


            DataSet ds = ClassDbOperator.RetrieveBySQLStr(strSql);


            dt = ds.Tables[ClassDbOperator.TEMPTABLE];

            if (dt.Rows.Count > 0)
            {
                BtnDownload.Visible = true;
                bool bb = true;

                GridView1.DataSource = dt;
                GridView1.DataBind();
                Session["sesdb"] = dt;
                return;
            }

            Response.Redirect("Download.aspx");

        }

        else
        {     

        }

}


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView1.BottomPagerRow.Visible = true;
       
        GridView1.PageIndex = e.NewPageIndex;
        
        bindgrid();
        
     
        
        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        bindgrid();
           
           

    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.