简体   繁体   中英

NotSupportedException was unhandled (gridview C#)

I am trying to display my data in a gridview. It works fine, until . . . . . I want to do paging (20 data per page), it causes an error NotSupportedException was unhandled .

How do i solve this?

This is my code. I also have set paging to 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.

Please remove the code from the PageIndexChanging event & see what happens.

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. This must not be done.

You don't need to do anything explicit to handle paging in datagrid, except to set a few properties. Read some intro tutorials on how to handle paging in datagrid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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