PageIndexChanging in GridView in ASP.NET

后端 未结 4 2095
我寻月下人不归
我寻月下人不归 2021-02-05 05:09

I have a gridview which I am using to display a dataset result. The problem is I am using paging in it. But when I click on the page # it says that I haven\'t handled the event.

4条回答
  •  孤独总比滥情好
    2021-02-05 05:53

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

提交回复
热议问题