【问题标题】:ASP.Net GridView UpdatePanel Paging Gives Error On Second ClickASP.Net GridView UpdatePanel 分页在第二次单击时出错
【发布时间】:2010-03-25 22:20:34
【问题描述】:

我正在尝试在 UpdatePanel 中实现带有分页的 GridView。当我第一次点击时,一切都很好。分页开始,下一组数据被快速加载。但是,当我尝试单击另一页数据的链接时,我收到以下错误:

Sys.WebForms.PageRequestManagerServerErrorException:处理服务器上的请求时发生未知错误。服务器返回的状态码是:12030

aspx 代码

    <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>

后面的代码

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

    }

关于导致第二次点击错误的任何线索?

【问题讨论】:

    标签: asp.net gridview paging


    【解决方案1】:

    如果您页面上 UpdatePanel 之外的任何内容在第一次单击后发生更改,或者尝试更改,在第二次单击时会有所不同,但是您的调用确实再次获得了第一个值,因为 UpdatePanel 之外并没有得到更新值,只是再次获取第一个 -> 所以在第二次点击时产生错误。

    可能您在 UpdatePanel 之外有一些需要正确呈现的数据。 将您更改并与此控件一起使用的任何内容保存在 UpdatePanel 中。

    例如 sSQL,你将它存储在哪里?它的变化?也许点击时其他值会发生变化?

    【讨论】:

    • sSQL 值和连接对象在 bindGridView 函数中定义和构建。我只是把它从发布的代码中删除了......我确实在 bindGridView 函数中移动了数据表的声明,但这似乎没有帮助。除了更新面板和网格视图之外,我还删除了页面中的所有内容,但它似乎仍然无法完全呈现或完成分页调用
    • 你对 ViewState 有什么动作吗?例如通过将其移动到页面底部?一般来说,如果您在任何模块中更改视图状态并且没有使其良好,updatePanel 第二次没有得到它 - 如果是的话告诉我告诉我一些技巧
    【解决方案2】:

    可能您在 UpdatePanel 之外有一些需要正确呈现的数据。将您更改并与此控件一起使用的任何内容保存在 UpdatePanel 中。

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2012-02-05
      相关资源
      最近更新 更多