GridView控件“GridView1”解雇事件PageIndexChanging这是不处理 [英] The GridView 'GridView1' fired event PageIndexChanging which wasn't handled

查看:136
本文介绍了GridView控件“GridView1”解雇事件PageIndexChanging这是不处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了:


  • 一个母版页和一个内容页调用的细节。

  • 在按钮点击事件,在网格视图中显示的数据。

  • 在网格视图中,列是自动生成的。

  • 我想表明在网格视图11列,但它比网页更
    大小。

什么为这个做什么?

我已经创建了数据库连接code SQL帮助文件,并调用该方法,不使用的SqlDataSource进行连接。

当我试图做分页,得到的错误


  

GridView控件GridView1解雇事件PageIndexChanging这是不
  处理的。



解决方案

您需要在您的code声明一个方法背后的处理PageIndexChanging事件。

类似这样:

 保护无效GridView1_PageIndexChanging(对象发件人,GridViewPageEventArgs E)
{
    GridView1.PageIndex = e.NewPageIndex;
    bindGridView(); // bindgridview将得到的数据源,并重新绑定
}私人无效bindGridView()
{
     GridView1.DataSource =的getData();
     GridView1.DataBind();
}

提供样品code:

 保护无效GridView1_PageIndexChanging(对象发件人,GridViewPageEventArgs E)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bindGridView(); // bindgridview将得到的数据源,并重新绑定
    }    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        如果(!的IsPostBack)
         bindGridView();    }
    //这是一些示例数据
    私人无效bindGridView()
    {
        数据表T =新的DataTable();
        t.Columns.Add(COL1);
        t.Columns.Add(col2的);
        DataRow的R = NULL;
        的for(int i = 0;我α25,我++)
        {
            R = t.NewRow();
            r.ItemArray =新的对象[] {瓦尔+我,另一个+ I};
            t.Rows.Add(R);
        }
        GridView1.DataSource = T;
        GridView1.DataBind();
    }

这是标记:

 < ASP:GridView的OnPageIndexChanging =GridView1_PageIndexChangingAllowPaging =真每页=10ID =GridView1=服务器的AutoGenerateColumns =真>

产生这样的:

I have created:

  • one master page and one content page called Detail.
  • On Button click event, displaying data in grid view.
  • In grid view, columns are autogenerated.
  • I wanted to show 11 column in grid view, but it is more than page size.

What to do for this?

I have created sql helper file for database connection code and calling that method, not using sqldatasource for connection.

When I trying to do paging, getting error:

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

解决方案

You need to declare a method on your code behind that handles the PageIndexChanging event.

Something similar to this:

protected void GridView1_PageIndexChanging (object sender, GridViewPageEventArgs  e)
{
    GridView1.PageIndex = e.NewPageIndex;
    bindGridView(); //bindgridview will get the data source and bind it again
}

private void bindGridView()
{
     GridView1.DataSource=getData();
     GridView1.DataBind();
}

Providing sample code:

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bindGridView(); //bindgridview will get the data source and bind it again
    }

    protected void Page_Load(object sender , EventArgs e)
    {
        if(!IsPostBack)
         bindGridView();

    }
    //this is some sample data 
    private void bindGridView()
    {
        DataTable t = new DataTable();
        t.Columns.Add("Col1");
        t.Columns.Add("Col2");
        DataRow r = null;
        for (int i = 0; i < 25; i++)
        {
            r = t.NewRow();
            r.ItemArray = new object[] { "Val" + i, " Another " + i };
            t.Rows.Add(r);
        }
        GridView1.DataSource = t;
        GridView1.DataBind();
    }

And this is the markup:

<asp:GridView OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="true" PageSize="10" ID="GridView1" runat="server" AutoGenerateColumns="true">

Produces this:

这篇关于GridView控件“GridView1”解雇事件PageIndexChanging这是不处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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