【问题标题】:Sorting data table after update更新后排序数据表
【发布时间】:2016-08-28 08:08:51
【问题描述】:

我正在使用绑定到我页面上的 gridView 的数据表。用户可以删除和修改 gridView 行,以便在每次更改后对每一行进行排序。 gridView后面的dataTable按两个字段升序排列。一个对组中的每个元素进行计数,另一个对组索引进行排序。

用户可以删除组,但是数字的顺序就搞砸了。我需要的是每次删除一个组时重新索引表,以便我有没有间隙的序列号:

例如:

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;
}

【问题讨论】:

    标签: c# asp.net sorting gridview datatable


    【解决方案1】:

    您可以使用“DataTable”javascript 功能来解决这个问题。请参考https://www.datatables.net/

    它将通过在 javascript 中设置参数来设置您的排序问题。

    如果您需要进一步的帮助,请告诉我。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-14
      • 2015-12-18
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 2021-10-06
      相关资源
      最近更新 更多