private List <ItemRelationshipSort> FilterSortedItems(DataTable dt) { this._sortItems = new List <ItemRelationshipSort>(); foreach (DataRow dr in dt.Rows) { int sortOrder; if (Int32.TryParse(dr["SortOrder"].ToString(), out sortOrder) && sortOrder > 0) { var ir = new ItemRelationshipSort { ItemRelationshipId = Convert.ToInt32(dr["ItemRelationshipId"], CultureInfo.InvariantCulture), SortOrder = sortOrder, Name = dr["ChildName"].ToString() }; if (this._sortItems.Count > ir.SortOrder) { this._sortItems.Insert(ir.SortOrder, ir); } else { this._sortItems.Add(ir); } } } this.Session[SortList] = this._sortItems; return(this._sortItems); }
protected void lbMoveToSort_Click(object sender, EventArgs e) { // ReorderDataTable(); this._sortItems = this.Session[SortList] as List <ItemRelationshipSort>; this._unsortedItems = this.Session[UnSortedList] as List <ItemRelationshipSort>; DataTable selectedRelationship = ItemRelationship.GetItemRelationshipByItemRelationshipId( Convert.ToInt32(this.lbCategoryItems.SelectedValue, CultureInfo.InvariantCulture)).Tables[0]; foreach (DataRow dr in selectedRelationship.Rows) { var irs = new ItemRelationshipSort { ItemRelationshipId = Convert.ToInt32(dr["ItemRelationshipId"], CultureInfo.InvariantCulture), SortOrder = Convert.ToInt32(dr["SortOrder"], CultureInfo.InvariantCulture), Name = dr["Name"].ToString() }; // If we've previously removed this from the _sortItems list we need to remove it from our session list of UnSorted items if (this._unsortedItems != null) { if (this._unsortedItems.Contains(irs)) { this._unsortedItems.Remove(irs); } } if (this._sortItems != null) { this._sortItems.Add(irs); } // remove item from original list } ListItem li = this.lbCategoryItems.SelectedItem; this.lbCategoryItems.Items.Remove(li); // Util.Utility.SortDataTableSingleParam(dt, "SortOrder ASC"); // get the already sorted items for a category this.rlCategorySort.DataSource = this._sortItems; this.rlCategorySort.DataBind(); this.Session[UnSortedList] = this._unsortedItems; this.Session[SortList] = this._sortItems; }
protected void rlCategorySort_Reorder(object sender, ReorderListItemReorderEventArgs e) { this._sortItems = this.Session[SortList] as List <ItemRelationshipSort>; if (this._sortItems != null) { ItemRelationshipSort irs = this._sortItems[e.OldIndex]; this._sortItems.Remove(irs); this._sortItems.Insert(e.NewIndex, irs); } this.rlCategorySort.DataSource = this._sortItems; this.rlCategorySort.DataBind(); this.Session[SortList] = this._sortItems; }