简体   繁体   English

未处理NotSupportedException(gridview C#)

[英]NotSupportedException was unhandled (gridview C#)

I am trying to display my data in a gridview. 我正在尝试在gridview中显示我的数据。 It works fine, until . 工作正常,直到。 . . . . I want to do paging (20 data per page), it causes an error NotSupportedException was unhandled . 我想进行分页(每页20个数据),它导致未处理NotSupportedException错误。

How do i solve this? 我该如何解决?

This is my code. 这是我的代码。 I also have set paging to true. 我还将分页设置为true。

public void bindGV()
    {
        string strCon = Database.GetConStr();
        SqlConnection sqlCon = new SqlConnection(strCon);
        SqlCommand sqlCommand = new SqlCommand("select * from Account", sqlCon);
        sqlCon.Open();

        SqlDataReader reader = sqlCommand.ExecuteReader();

        StaffGV.DataSource = reader;
        StaffGV.DataBind();
    }

    protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GV.PageIndex = e.NewPageIndex;
        bindGV();
    }

The error comes from the GV_PageIndex. 错误来自GV_PageIndex。

Please remove the code from the PageIndexChanging event & see what happens. 请从PageIndexChanging事件中删除代码,然后看看会发生什么。

Read your code again & it implies that - on every click of the next page, you would want to fetch the data from the database and bind it to the datagrid. 再次阅读代码,这意味着-每次单击下一页,您都希望从数据库中获取数据并将其绑定到datagrid。 This must not be done. 绝对不能这样做。

You don't need to do anything explicit to handle paging in datagrid, except to set a few properties. 除了设置一些属性外,您无需执行任何显式操作即可处理datagrid中的分页。 Read some intro tutorials on how to handle paging in datagrid. 阅读有关如何在datagrid中处理分页的一些入门教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM