0

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();
        
        
    }
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by arunmagnilagan
0

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

0

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();
           
           

    }

Edited by arunmagnilagan: modify the code

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.