views:

337

answers:

1

I'm trying to implement a GridView with paging inside a UpdatePanel. Everything works great when I do my first click. The paging kicks in and the next set of data is loaded quickly. However, when I then try to click a link for another page of data, I get the following error:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 12030

aspx code

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <contenttemplate>
        <asp:GridView ID="GridView1" runat="server" CellPadding="2" 
                AllowPaging="true" AllowSorting="true" PageSize="20"
                OnPageIndexChanging="GridView1_PageIndexChanging"
                OnSorting="GridView1_PageSorting"
                AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="ActivityLogID" HeaderText="Activity Log ID" SortExpression="ActivityLogID" />
                <asp:BoundField DataField="ActivityDate" HeaderText="Activity Date" SortExpression="ActivityDate" />
                <asp:BoundField DataField="ntUserID" HeaderText="NTUserID" SortExpression="ntUserID" />
                <asp:BoundField DataField="ActivityStatus" HeaderText="Activity Status" SortExpression="ActivityStatus" />
            </Columns>
        </asp:GridView>
    </contenttemplate>
</asp:UpdatePanel>

code behind

    private void bindGridView(string sortExp, string sortDir)
    {
        SqlCommand mySqlCommand = new SqlCommand(sSQL, mySQLconnection);
        SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlCommand);
        mySqlAdapter.Fill(dtDataTable);

        DataView myDataView = new DataView();
        myDataView = dt.DefaultView;

        if (sortExp != string.Empty)
        {
            myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
        }

        GridView1.DataSource = myDataView;
        GridView1.DataBind();

        if (mySQLconnection.State == ConnectionState.Open)
        {
            mySQLconnection.Close();
        }

    }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bindGridView();
    }
    protected void GridView1_PageSorting(object sender, GridViewSortEventArgs e)
    {

        bindGridView(e.SortExpression, sortOrder);

    }

any clues on what is causing the error on the second click?

A: 

If anything on your page that is outside UpdatePanel, is changing after the first click, or try to change, on second click is comething diferent, but your calls did get again the fist one value because there are outside UpdatePanel and did not get the update value, just get the first one again -> So product an error on second click.

Probably you have out side the UpdatePanel some data thats need to be rendered correctly. Keep inside UpdatePanel anything that you change and use with this control.

For example the sSQL, where do you store it ? Its change ? Maybe other value changes on click ?

Aristos
the sSQL value and the connection object are defined and built within the bindGridView function. i just left that out of the posted code...i did move the declaration of the data table inside the bindGridView function, but that didn't appear to help. i also stripped everything out of the page except for the update panel and gridview, but it still seems to have problem fully rendering or completing the paging call
joe
Do you make any move of the ViewState ? eg by moving it on bottom of the page ? In general if you change in any module, the viewstate and not make it good, the updatePanel did not get it the second time - if yes tell me so to tell some tricks
Aristos