编辑gridview不会保留原始排序顺序 [英] Editing gridview doesnt keep the original sort order
问题描述
我无法对表格进行排序:
我正在做一个示例项目,如文章中所示: http://www.dotnetfunda.com/articles/article18.aspx
这是一个简单的网格视图,在我的aspx.cs文件中具有编辑和排序功能
对于每个数据绑定,数据都是从数据库中获取的(例如,在dataediting上)
如果我先对我的数据进行排序,然后再尝试编辑,则整个排序顺序将丢失.因此我添加了自己的想法,即在给出数据表之前检查是否有任何先前的排序操作.
在下面的代码中,我的dataview.sort函数正在工作,但是我的返回Table1返回未排序的表,而不是我使用dataview1.ToTable("Table1")分配的表.声明.
:(
I have trouble sorting table:
i am doing a sample project as show in article:http://www.dotnetfunda.com/articles/article18.aspx
This a simple grid view with editing and sorting functions in my aspx.cs file
for every data bind the data is taken fresh from database(for example on dataediting )
if i sort my data first and then try to edit the whole sort order will be lost. so i added my own idea of checking for any previous sort action before the datatable is given out.
In the below code my dataview.sort function is working but my return Table1 is returning the unsorted table not the one that i assigned using dataview1.ToTable("Table1"); statement.
:(
private DataTable GridEmployeeDataSource()
{
Class1 DALobj = new Class1();
DataTable Table1;
try
{
// System .Data.DataTable =
Table1 = DALobj.Load();
//before giving table out check if it was previously ever sorted
//
if (ViewState["SortExpression"] != null)
{
if (ViewState["SortDirection"] != null)
{
DataView dataview1 = new DataView(Table1);
string sortexpression = ViewState["SortExpression"].ToString();
string sortdirection = ViewState["SortDirection"].ToString();
dataview1.Sort = sortexpression +" "+ sortdirection;
dataview1.ToTable("Table1");
}
}
return Table1;
}
catch (Exception ee)
{
lblErroMessage.Text = ee.Message.ToString();
return null;
}
}
推荐答案
YEEEEEEEEEEEEEY
修复了
:)
instedof 返回表1 我使用了返回 dataview1.ToTable("Table1")
YEEEEEEEEEEEEEY
Fixed it
:)
instedof return Table1 i used return dataview1.ToTable("Table1")
这篇关于编辑gridview不会保留原始排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!