The page uses the CatalogNodeCollection to populate a listbox that is resorted through javascript calls to the functions UP(int) and DN(int). The javascript functions are responsible for reordering the listbox, and the SaveButton_Click event reads the resulting listbox state and attempts to save the changes.
The bug is in how these list items are created.
Code: Select all
<asp:ListBox ID="CatalogNodeList" runat="server" DataTextField="Name" DataValueField="CatalogNodeId" Rows="20">
</asp:ListBox>
Code: Select all
public enum CatalogNodeType
{
Category = 0,
Product = 1,
Webpage = 2,
Link = 3,
}
Assume we have 2 categories and 4 products:
Category A (Id = 1)
Category B (Id = 2)
Product 1 (Id = 1)
Product 2 (Id = 2)
Product 3 (Id = 3)
Product 4 (Id = 4)
Their current sort order in the listbox is such:
Category A (Id = 1)
Product 1 (Id = 1)
Category B (Id = 2)
Product 2 (Id = 2)
Product 3 (Id = 3)
Product 4 (Id = 4)
If we use the FIRST, ^,v, and LAST buttons, we see that the item moves appropriately up and down the list. If we move Category B to the top, we now have:
Category B (Id = 2)
Category A (Id = 1)
Product 1 (Id = 1)
Product 2 (Id = 2)
Product 3 (Id = 3)
Product 4 (Id = 4)
Then we click save. But we notice that Category B moves back above Product 2. Why? Lets look at the SaveButton_Click code:
Code: Select all
protected void SaveButton_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(SortOrder.Value))
{
2,1,1,2,3,4
Lets see what happens next in the SaveButton_Click:
Code: Select all
CatalogNodeCollection catalogNodes = _CatalogNodes;
string[] catalogNodesIds = SortOrder.Value.Split(",".ToCharArray());
int order = 0;
int tempId = 0;
int index = -1;
foreach (string sPartId in catalogNodesIds)
{
foreach (CatalogNode cn in _CatalogNodes)
{
tempId = AlwaysConvert.ToInt(sPartId);
if (cn.CatalogNodeId == tempId)
{
index = catalogNodes.IndexOf(cn);
if (index > -1)
catalogNodes[index].OrderBy = (short)order;
order++;
}
}
}
catalogNodes.Save();
}
Response.Redirect("Browse.aspx?CategoryId=" + _CategoryId.ToString());
}
Has this bug been reported? Is there an expected release of a fix?