ASP.Net GridView的UpdatePanel分页给第二次点击错误 [英] ASP.Net GridView UpdatePanel Paging Gives Error On Second Click

查看:126
本文介绍了ASP.Net GridView的UpdatePanel分页给第二次点击错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在UpdatePanel中实现一个带分页的GridView。当我做第一次点击时,一切都很好。分页开始并快速加载下一组数据。但是,当我尝试点击另一页数据的链接时,出现以下错误:
$ b Sys.WebForms.PageRequestManagerServerErrorException:发生未知错误同时在服务器上处理请求。从服务器返回的状态代码是:12030

aspx code

 < asp:UpdatePanel ID =UpdatePanel1runat =server> 
< contenttemplate>
< asp:GridView ID =GridView1runat =serverCellPadding =2
AllowPaging =trueAllowSorting =truePageSize =20
OnPageIndexChanging = GridView1_PageIndexChanging
OnSorting =GridView1_PageSorting
AutoGenerateColumns =False>
<列>
< asp:BoundField DataField =ActivityLogIDHeaderText =Activity Log IDSortExpression =ActivityLogID/>
< asp:BoundField DataField =ActivityDateHeaderText =Activity DateSortExpression =ActivityDate/>
< asp:BoundField DataField =ntUserIDHeaderText =NTUserIDSortExpression =ntUserID/>
< asp:BoundField DataField =ActivityStatusHeaderText =Activity StatusSortExpression =ActivityStatus/>
< /列>
< / 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();


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


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

解决方案

可能你有UpdatePanel的某些数据需要正确呈现。保留在UpdatePanel里面的任何东西,你改变和使用这个控制。


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?

解决方案

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.

这篇关于ASP.Net GridView的UpdatePanel分页给第二次点击错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆