GridView'GridView1'触发了未处理的事件PageIndexChanging. [英] The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

查看:91
本文介绍了GridView'GridView1'触发了未处理的事件PageIndexChanging.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gridview,并且想使用分页.我已经将允许分页设置为true,将页面大小设置为5.我可以在gridview的底部看到数字,但是当我单击一个数字移动到相应的页面时,它会抛出错误:

I am using a gridview and I want to use paging. I have already set allow paging to true and page size to 5. I can see the numbers at the base of my gridview, but when i click on a number to move to respective page, it throws an error saying:

The GridView ''GridView1'' fired event PageIndexChanging which wasn''t handled.

推荐答案

您可以执行以下任务来实现此目的.

1)创建一个类级别的静态DataTable

You can to do following task to achieve this.

1) create a class level static DataTable

static DataTable dtDataForGrid= new DataTable();



2)在Page_Load方法中,填充DataTable dtDataForGrid并将其与GridView绑定.




2)In the Page_Load method , fill DataTable dtDataForGrid and bind it with GridView.


dtDataForGrid.Rows.Clear();

  //code to fill the DataTable dtDataForGrid

GridView1.DataSource = dtDataForGrid;
GridView1.DataBind();



3)完成上述工作后.生成GridView1_PageIndexChanging事件.并编写以下代码.



3) After doing above job. generate the GridView1_PageIndexChanging event. and write the following code.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       GridView1.PageIndex = e.NewPageIndex;
       GridView1.DataSource = dtDataForGrid;
       GridView1.DataBind();

   }




希望这对您有所帮助.

谢谢,
Arshad




hope this will help you out.

Thanks,
Arshad


所以,

创建网格视图的pageindexchange事件,并将新的页面索引分配给网格视图.


So,

create event of pageindexchange of grid view and assign the new page index to grid view.


protected void GridSummary_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            if (e.NewPageIndex != -1)
            {
                GridSummary.PageIndex = e.NewPageIndex;
                // Call the method to assing datasource to grid view again
            }
            else
            {
                
            }
        }
        catch
        {
        }

    }


这篇关于GridView'GridView1'触发了未处理的事件PageIndexChanging.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆