/// <summary> /// 跨页保持选中项 - 根据隐藏字段的数据更新表格当前页面的选中行 /// </summary> /// <param name="hfSelectedIDS"></param> /// <param name="grid"></param> public void UpdateSelectedRowIndexArray(FineUIPro.HiddenField hfSelectedIDS, Grid grid) { List <int> ids = GetSelectedIDsFromHiddenField(hfSelectedIDS); List <int> nextSelectedRowIndexArray = new List <int>(); if (grid.IsDatabasePaging) { for (int i = 0, count = Math.Min(grid.PageSize, (grid.RecordCount - grid.PageIndex * grid.PageSize)); i < count; i++) { int id = Convert.ToInt32(grid.DataKeys[i][0]); if (ids.Contains(id)) { nextSelectedRowIndexArray.Add(i); } } } else { int nextStartPageIndex = grid.PageIndex * grid.PageSize; for (int i = nextStartPageIndex, count = Math.Min(nextStartPageIndex + grid.PageSize, grid.RecordCount); i < count; i++) { int id = Convert.ToInt32(grid.DataKeys[i][0]); if (ids.Contains(id)) { nextSelectedRowIndexArray.Add(i - nextStartPageIndex); } } } grid.SelectedRowIndexArray = nextSelectedRowIndexArray.ToArray(); }
/// <summary> /// 跨页保持选中项 - 将表格当前页面选中行对应的数据同步到隐藏字段中 /// </summary> /// <param name="hfSelectedIDS"></param> /// <param name="grid"></param> public void SyncSelectedRowIndexArrayToHiddenField(FineUIPro.HiddenField hfSelectedIDS, Grid grid) { List <int> ids = GetSelectedIDsFromHiddenField(hfSelectedIDS); List <int> selectedRows = new List <int>(); if (grid.SelectedRowIndexArray != null && grid.SelectedRowIndexArray.Length > 0) { selectedRows = new List <int>(grid.SelectedRowIndexArray); } if (grid.IsDatabasePaging) { for (int i = 0, count = Math.Min(grid.PageSize, (grid.RecordCount - grid.PageIndex * grid.PageSize)); i < count; i++) { int id = Convert.ToInt32(grid.DataKeys[i][0]); if (selectedRows.Contains(i)) { if (!ids.Contains(id)) { ids.Add(id); } } else { if (ids.Contains(id)) { ids.Remove(id); } } } } else { int startPageIndex = grid.PageIndex * grid.PageSize; for (int i = startPageIndex, count = Math.Min(startPageIndex + grid.PageSize, grid.RecordCount); i < count; i++) { int id = Convert.ToInt32(grid.DataKeys[i][0]); if (selectedRows.Contains(i - startPageIndex)) { if (!ids.Contains(id)) { ids.Add(id); } } else { if (ids.Contains(id)) { ids.Remove(id); } } } } hfSelectedIDS.Text = new JArray(ids).ToString(Formatting.None); }
/// <summary> /// 从隐藏字段中获取选择的全部ID列表 /// </summary> /// <param name="hfSelectedIDS"></param> /// <returns></returns> public List <int> GetSelectedIDsFromHiddenField(FineUIPro.HiddenField hfSelectedIDS) { JArray idsArray = new JArray(); string currentIDS = hfSelectedIDS.Text.Trim(); if (!String.IsNullOrEmpty(currentIDS)) { idsArray = JArray.Parse(currentIDS); } else { idsArray = new JArray(); } return(new List <int>(idsArray.ToObject <int[]>())); }