views:

106

answers:

1

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.

+1  A: 

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.

shahkalpesh
By doing so, I still do have the same error. Why is this so?
Nana
shahkalpesh