GridView“GridView1”触发了未处理的 PageIndexChanging 事件

发布于 2024-12-12 17:27:58 字数 365 浏览 0 评论 0原文

我创建了:

  • 一个母版页和一个名为“详细信息”的内容页。
  • 在按钮单击事件上,在网格视图中显示数据。
  • 在网格视图中,列是自动生成的。
  • 我想在网格视图中显示 11 列,但它比页面多 尺寸。

为此该怎么办?

我已经为数据库连接代码创建了 sql 帮助程序文件并调用该方法,而不是使用 sqldatasource 进行连接。

当我尝试进行分页时,出现错误

GridView“GridView1”触发了 PageIndexChanging 事件,但事实并非如此 已处理。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

装纯掩盖桑 2024-12-19 17:27:58

您需要在后面的代码中声明一个处理 PageIndexChanging 事件的方法。

与此类似的内容:

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

提供示例代码:

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

这是标记:

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

生成以下内容:

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:

enter image description here

影子是时光的心 2024-12-19 17:27:58

对于分页,您可以使用 OnPageIndexChanging...

例如,

您必须在 GridView 中使用 OnPageIndexChanging="gvdetails_PageIndexChanging"...

您必须将以下代码写入代码后面的事件中,如了解

protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvdetails.PageIndex = e.NewPageIndex;
    BindData();
}

更多详细信息您可以在此处查看以下链接我在我的文章中使用页面索引更改...

这里我使用PageIndexChange

我希望这会对您有所帮助....与其他人分享...谢谢!

For Paging you can use OnPageIndexChanging for this....

For Example

you have to use OnPageIndexChanging="gvdetails_PageIndexChanging" in your GridView...

You have to write below code into event in code behind like

protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvdetails.PageIndex = e.NewPageIndex;
    BindData();
}

For more detail you can check the below link here I am using page Index change in my article...

Here I use PageIndexChange

I hope this will helps you....Share it with others...Thanks!

〆凄凉。 2024-12-19 17:27:58

这是最终的答案:

Imports System.Collections.Generic ' library

Protected Sub grdEmployees_PageIndexChanging1(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdEmployees.PageIndexChanging
    grdEmployees.PageIndex = e.NewPageIndex
    LoadEmployeeList() 'FUNCTION FOR DATASET
    grdEmployees.DataBind()

End Sub

This is the final answer:

Imports System.Collections.Generic ' library

Protected Sub grdEmployees_PageIndexChanging1(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdEmployees.PageIndexChanging
    grdEmployees.PageIndex = e.NewPageIndex
    LoadEmployeeList() 'FUNCTION FOR DATASET
    grdEmployees.DataBind()

End Sub
贱贱哒 2024-12-19 17:27:58

您只需将其添加到您的代码中:

protected void GridViewTrsEmail_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridViewTrsEmail.PageIndex = e.NewPageIndex;
    GridViewTrsEmail.DataBind();


}

you simply add this to your code :

protected void GridViewTrsEmail_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridViewTrsEmail.PageIndex = e.NewPageIndex;
    GridViewTrsEmail.DataBind();


}
蓦然回首 2024-12-19 17:27:58

为了解决这个问题,我必须仔细查看我的数据源和数据键。我有一组从 SQL Server 返回的记录,我所做的是将它们绑定到 POCO。该类有几个 Integer 类型的公共属性。这些整数是我在网格上的数据键。我用字符串替换了它们的类型,以绕过转换问题。

To fix this, I had to take a closer look at my datasource and datakeys. I have a set of records that are returned from SQL Server and what I was doing is binding them to a POCO. This class had several public properties of type Integer. These Integers were my datakeys on the grid. I replaced their type with a string instead to bypass the casting issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文