Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm exploring how to build a Visual Web Part, that in edit mode, allows me to apply a custom sort order on a list of items.

For simplicity, assume that when I load the web part, I can populate a List<string> with some values.

When I edit the web part in the edit view of the page it's in, I'd like to allow the user to sort the items however they'd like - ideally using something like http://jqueryui.com/demos/sortable/.

I can check the DesignMode property of the web part to see if the web part is in design mode, and if so, show an appropriate UI to do the sorting.

However, I can't think of a good mechanism to store the data after sorting it, and more importantly display the data when the web part is no longer in design mode.

I have to also consider what would happen if an item was added/removed to the underlying List<string>. I would need to reconcile the underlying List<string> with the data structure that contains the sorted data.

Appreciate any tips, thank you!

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

On my opinion there are two possible solutions.

  1. You can create an ajax handler and track drag and drop events on UI. When web part in edit mode and element position changed you send async request to server and update web part properties accordingly.
  2. The other way (and this is more preferable way I think) is to create a custom tool part. When you create a custom tool part you need to overload two methods - SyncChanges and ApplyChanges. ApplyChanges method fires when you click "Ok" or "Apply" buttons in web part tool pane in edit mode. In this method you can access to Request.Form values. So, you can save your new sort order in some hidden input in html, then read and parse this value in ApplyChanges and update web part property.
share|improve this answer
    
Kai, I'm going to look into creating a custom EditorPart that loads a specific user control. Thanks for the tip. –  George Durzi Dec 19 '11 at 18:58
    
Thanks Kai, the EditorPart was the way to go. –  George Durzi Dec 27 '11 at 1:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.