Pregunta

Tengo un gridview el que estoy usando para mostrar el resultado conjunto de datos. El problema es que estoy usando paginación en ella. Sin embargo, al hacer clic en la página # dice que no he manejado el caso. ¿Es necesario volver a vincular el conjunto de datos ???

Gracias

¿Fue útil?

Solución

Pruebe el siguiente código:

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

Otros consejos

Try it

In the pageload

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

In the pageindexchanging

private void loadGrid()
{
    using (your_bankEntities context = new your_bankEntities()) //use your connection .edmx
    {
        var jmDados = (from jm in context.yourdbo  orderby jm.your fieldkey  
                         select new
                           {
                               jm.Field1,
                               jm.Field2,
                               jm.Field3,
                               jm.Field4,
                               ........ 
                               jm.n

                           }).ToList();
        GridView1.DataSource = jmDados;

        GridView1.DataBind();
    }
}

In the pageindexchanging

GridView1.PageIndex = e.NewPageIndex;

loadGrid();

In VB.net, it does not have much difference with C#, you just remove the semicolons at the end of each line

Private Sub myGridview_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles myGridview.PageIndexChanging

   LoadGridView() //Call your method to load the data into the grid.
   myGridview.PageIndex = e.NewPageIndex
   myGridview.DataBind()

End Sub

You should set the .PageIndex before binding data! Otherwise, you would need extra clicks which actually double the BindData method calls. The following is my tested vb code.

Private Sub GridViewL_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridViewL.PageIndexChanging

    GridViewL.PageIndex = e.NewPageIndex
    BindData()  ' your method to bind data to the grid
End Sub
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top