Back-end Management Tasks for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Moving Tree Nodes
(Page 2 of 6 )
Moving the Tree Nodes
Here, we merge the two click event handlers for the "Move Upward" and "Move Downward" buttons together into one, as is indicated in the following code:
protected void MoveBtn_Click(object sender,EventArgs e){
string sCommandName = ((Button)sender).CommandName;
if(CategoryView.SelectedNode == null) {
Response.Write("<script>window.alert('Please select the item.')
</script>");
return;
}
///define the class
Category category = new Category();
///edit data
category.UpdateCategoryOrder(Int32.Parse
(CategoryView.SelectedNode.Value),sCommandName);
BindCategoryData();
}
Obviously, the user must first select one of the tree nodes, and then click the related button, or he will get a corresponding warning. Note the moving operation is in fact to sort the product categories. If the category node is selected and the moving button is clicked, then the UpdateCategoryOrder methodof the Categoryclass is invoked to accomplish the related movement.
Deleting the Tree Nodes
Here’s the code related to the deletion operation.
protected void DeleteBtn_Click(object sender,EventArgs e){
if(CategoryView.SelectedNode == null){
Response.Write("<script>window.alert('Please select the item.')</script>");
return;
}
if(CategoryView.SelectedNode.ChildNodes.Count > 0){
Response.Write("<script>window.alert('The node you are to delete still
includes sub nodes and cannot be deleted!')</script>");
return;
}
///define the class
Category category = new Category();
///delete data
category.DeleteCategory(Int32.Parse(CategoryView.SelectedNode.Value));
BindCategoryData();
///display the info of the operating result
//Response.Write("<script>window.alert('You have succeeded in deleting
data.')</script>");
}
As with the moving operation above, only if the related node is selected can the node be deleted; otherwise, the user will still receive a warning. Note here if the selected node has its child nodes, then it can not be deleted, i.e. the user can only directly delete the leaf node on the tree.
Please note here that we've chosen to leave out discussion of the adding and modifying categories operations.
Next: Product Management >>
More ASP.NET Articles
More By Xianzhong Zhu