繁体   English   中英

行编辑时,ASP Net Gridview排序消失

[英]Asp Net Gridview sort disapears when row edit

当我单击更新行时,gridview消失了,并返回到其初始状态。 可以是什么? 下面抄写我的代码:

  private string GetSortDirection(string column)
    {

        // By default, set the sort direction to ascending.
        string sortDirection = "ASC";

        // Retrieve the last column that was sorted.
        string sortExpression = ViewState["SortExpression"] as string;

        if (sortExpression != null)
        {
            // Check if the same column is being sorted.
            // Otherwise, the default value can be returned.
            if (sortExpression == column)
            {
                string lastDirection = ViewState["SortDirection"] as string;
                if ((lastDirection != null) && (lastDirection == "ASC"))
                {
                    sortDirection = "DESC";
                }
            }
        }

        // Save new values in ViewState.
        ViewState["SortDirection"] = sortDirection;
        ViewState["SortExpression"] = column;

        return sortDirection;
    }

    protected void GridViewLayoutProduto_Sorting(object sender, GridViewSortEventArgs e)
    {
        //Retrieve the table from the session object.
        DataTable dt = Session["TaskTable"] as DataTable;

        if (dt != null)
        {
            //Sort the data.
            dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
            Session["TaskTable"] = dt;
            GridViewLayoutProduto.DataSource = Session["TaskTable"];
            GridViewLayoutProduto.DataBind();
        }
    }

    protected void GridViewLayoutProduto_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridViewLayoutProduto.EditIndex = e.NewEditIndex;
        //CheckBox alt = GridViewLayoutProduto.Rows[e.NewEditIndex].FindControl("CheckBox1") as CheckBox;
        //alt.Enabled = false;
        BindData();
    }

    protected void GridViewLayoutProduto_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridViewLayoutProduto.PageIndex = e.NewPageIndex;
        GridViewLayoutProduto.DataBind();
    }

    protected void GridViewLayoutProduto_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridViewLayoutProduto.EditIndex = -1;
        BindData();
    }

    private void BindData()
    {
        GridViewLayoutProduto.DataSource = Session["TaskTable"];
        GridViewLayoutProduto.DataBind();
    }

在会话数据中,要存储的数据表将无法组织,如何在执行了datatble排序的情况下存储在会话中。

尝试在GridView排序后放置此行

Session["TaskTable"] = ((DataView)gvProgramlar.DataSource).ToTable();

希望这对您有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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