Why does not the pageindexchanging gridview event work for me?

0

Hi, I have a gridview in asp .net and I use the following code to change the page in the griview and it does not work.

This is my code:

<asp:GridView ID="grid1" runat="server" AutoGenerateColumns="False"  
AllowPaging="True" OnPageIndexChanging="grid1_PageIndexChanging"   
PageSize="7" />

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
       {
            FillGrid();
       }
    }

void FillGrid() {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ToString());
            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT * from tabla where cod_u='"+Session["Cod_u"]+"', con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            grid1.Visible = true;
            grid1.DataSource = dt;
           grid1.DataBind();
        }

 protected void grid1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

       grid1.PageIndex = e.NewPageIndex;
        FillGrid();
    }

I've also tried it this way:

protected void grid1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
      FillGrid();
       grid1.PageIndex = e.NewPageIndex;
      grid1.DataBind();
    }

and it does not work.

Thanks for reading

    
asked by sunflower 19.03.2018 в 20:38
source

0 answers