1
I have my Gridview
developed manually, the problem and that when I click to carry out the update
my gridview
ceases to be orderly and returns to its normal state. I intended that this would not happen.
Here I demonstrate how it is defined:
protected void CarregaGV(DateTime data,int tipo,string tipoSande)
{
DataTable dt = null;
dt = TrataDados.GetDetailsProductLayout(data, tipo,tipoSande);
Session["TaskTable"] = dt;
GridViewLayoutProduto.DataSource = dt;
GridViewLayoutProduto.DataBind();
}
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);
sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
//Session["TaskTable"] = ((DataView)GridViewLayoutProduto.DataSource).ToTable();
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();
}
I think the problem lies in Session
["Tasktable"] because I always keep the original state of Grid I think.
dt.Totable does not exist at least gives me error.
– user6018
I corrected it. I edited the code.
– Isaac Junior