当我点击该行更新时,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();
}
在会话数据中将不会组织要存储的数据表,如何在执行数据类型的会话中存储。
答案 0 :(得分:0)
尝试在排序GridView
Session["TaskTable"] = ((DataView)gvProgramlar.DataSource).ToTable();
希望这能帮到你!