0
我正在使用绑定到我的页面上的gridView的dataTable。用户可以删除和修改gridView行,以便在每次更改后对每行进行排序。 gridView后面的数据表按两个字段的升序排序。一个用于计算组中每个元素的值,另一个用于对组索引进行排序。更新后排序数据表
用户可以删除组,但数字的顺序则会被搞乱。
例如:
group id group id sorted
0 0
0 0
0 0
1 1
1 1
3 2
3 2
6 3
6 3
我试过这个功能,但室内用任何结果(我什么,我需要每次一组被删除,这样我有序列号,无缝隙是重新索引的表预计)。也许有人已经解决了这个问题,并可以提供帮助。
protected void reindexGroupsLayers(DataTable dtLayers)
{
//after every change to the index structure
//this function re-sorts the index
DataView uniqueGroupIndexesView = new DataView(dtLayers);
uniqueGroupIndexesView.Sort = "groupindex asc";
DataTable uniqueGroupIndexesTable = uniqueGroupIndexesView.ToTable(true, "groupindex");
int i = 0;
foreach (DataRow uniqueRow in uniqueGroupIndexesTable.Rows)
{
int oldIndex = (int)uniqueRow["groupindex"];
foreach (DataRow groupRow in dtLayers.Rows)
{
if ((int)groupRow["groupindex"] == oldIndex)
{
groupRow["groupindex"] = i;
}
else
{
continue;
}
i++;
}
}
DataView dtLayersView = dtLayers.DefaultView;
dtLayersView.Sort = "groupindex, layerindex asc";
DataTable dtLayersSorted = dtLayersView.ToTable();
gvMapLayers.DataSource = dtLayersSorted;
gvMapLayers.DataBind();
Session["webmaplayers"] = dtLayersSorted;
}