How to page GridView in Asp.net C #?

0

I have a gridview with a pagination, it works fine until page 9 but when I select 10 or more it sends me the error "The index was out of range, it should be a non-negative value and less than the size of the collection."

I attach my code

 <asp:TemplateField>
 <ItemTemplate>
 <%-- <asp:CheckBox ID="ChkEliminar" runat="server" />--%>
 <asp:Button ID="btnObservar" runat="server" Text="Observar" 
 CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"  
 CommandName="cmObservar" OnClientClick="return confirm('¿Esta Seguro que 
 desea Observar el Registro?');" />
</ItemTemplate>
</asp:TemplateField>



protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //obtener y recuperar el indice de una fila
        int index = Convert.ToInt32(e.CommandArgument);
        string NumPlanilla = GridView1.Rows[index].Cells[0].Text;



        Session["NumPlanilla"] = NumPlanilla;

        if (e.CommandName == "cmObservar")
        {
            if (!Validar())
                return;

            vRegistraValida.B_RegistraAprobacionrh(9, txtobserva.Text, Session["Usuario"].ToString(), "", "", "", "", 
                                                   Convert.ToInt32(DdlLote.SelectedValue), Convert.ToInt32(NumPlanilla));

            GridView1.Rows[index].Cells[11].Enabled = false;
            txtobserva.Text = "";

    
asked by Cecilia 28.07.2018 в 03:06
source

0 answers