ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [ASP.NET AJAX] ReorderList with ObjectDataSource (ReorderList 예제)
    .NET/ASP.NET AJAX 2009. 7. 29. 09:55
    반응형

    horovitz 의 .net Programming 3.5를 따라하다가 

    오류가 났다(해결이 힘들었다 그래서 다른 리오더리스트 예제를 삽질하다가~ 찾은 블로그..

    http://weblogs.asp.net/justinsaraceno/archive/2008/02/22/reorderlist-with-objectdatasource.aspx

    저스틴이라는  친구의 예제는 실행이 되는데 

    중요한것은

    IE 8에서는 작동을 하지 않는것이다.(IE 7에서는 작동한다) 크롬 2와 파이어폭스 3에서는 작동한다.

     http://app.lightstreamer.com/AtlasDemo/ <-- 여기 이사이트도 그렇다

    그래서 몇일? 동안 삽질하다가 문제점을 찾아냈다

    그것은 바로 내 개발 환경이 비주얼 스튜디오 2008 3.5 이라는데 있다.

    거기에 참조하는 AJAXControlToolkit.DLL파일에 문제가 있었다 (그 친구가 작성한것은 2005용 컨트롤툴킷인듯..)

    web.config를 수정하고 3.5용 Dll로 바꾸니 IE에서도 깔끔하게 작동한다

    아래는 내가 수정한 예제

    .net 3.5용이다 ㅎㅎ


    실행화면과  예제






















    아래는 원문과 예제

    http://weblogs.asp.net/justinsaraceno/archive/2008/02/22/reorderlist-with-objectdatasource.aspx

    저스틴 친구가 만든 예제 ㅋㅋ


    ReorderList with ObjectDataSource

    If you ask me, the AJAX Control Toolkit's ReorderList is the most under appreciated control in the Toolkit.  Compared to many of the other controls, it gets no love.  The Toolkit demo site's sample for this control isn't really all that helpful and third party samples are sparse.  And how do you bind it with an ObjectDataSource control?  Read on to find out... 

    The ReorderList had a 'real word' use for me.  There was a situation where I inherited a web form with a priority ranked list that was composed of a list of items that each had a textbox control to the left of them.  The textbox contained the priority order for the item in the list.  If the user wanted to change the order, he or she would change the numbers in the textboxes and then press a Save button which updated the priority order for the list.  Obviously, the users were having a difficult time making this work. 

    In comes the ReorderList, the magical key to this situation.  But how does this work; the Toolkit sample site didn't go far enough.  I wanted to bind this with an ObjectDataSource control and it just wasn't working.  Well I eventually figured it out and the first thing I thought of was I needed to write an article about this.  Of course this was over 6 months ago but now that I have this blog I thought that someone may benefit from my pain.

    I am including the sample project for this but let's walk through it. 
    First thing's first - we need some data to reorder.  How about a Wish List?  The below image shows a WishList table which is included in the project in a SQLExpress database.  There are only three columns: WishID (uniqueidentifier) which is the primary key; WishDescription (varchar) which is the wish text; and WishOrder (int) which holds the order of my wishes.  It is pictured here:

    DatabseTable

    So next create a class in App_Code for the ObjectDataSource to bind to.  I've called it ReorderClass.  First we need to have a method return a DataSet containing the wish data in from the database.  Here is the code for that: 
    DatasetCode 



    Since the order number from the ReorderList needs to be saved back in the database, we also need an Update method for our ObjectDataSource control.  The key here that many people miss is the Update method MUST have a method parameter for each of the data items that were selected in the above DataSet.  Not only is that true, but the method signatures must also be the same data type of the items returned from the Select method's DataSet.  Yes, even if you are not updating all the fields, you still need all the Selected fields in the Update method's signature.  So the DataSet in the Select method returned WishID, WishDescription, and WishOrder.  So, this Update method needs all three of those fields in its method signature.  The three method parameters are WishID which is of type Guid, WishDescription of type string, and WishOrder of type integer.  The code for this is here: 

    UpdateCode

    Now it's time for the ReorderList control.  You can bind data to the ReorderList but unlike the GridView control, there is no built-in auto binding option.  You have to create the template to bind the data to.  Here I've created a table for that contains the Wish Order number and Wish Description.  Also note that the ReorderList has properties including SortOrderField and DataKeyField.  The SortOrderField needs to be bound to the data item containing the sort order for your items.  The DataKeyField needs to be bound to your data item's identifier field (most likely its primary key in the database).

    ControlCode

    Now we're going to bind this to an ObjectDataSource control.  Notice that the Select Method is the method that returns the DataSet.  Also notice that the UpdateParameters match the fields that were in the Select statement.  Since there is no option for Type of uniqueidentifier, the wishID Parameter has been set to type of Object.

    DataSourceCode

    Now that it's all together, it will load, reorder, and save the reorder.

    image 

    It's not the simplest tool in the Toolkit to use but it is one of the coolest for sure.

    Attachment: ReorderListSample.zip
    Published Friday, February 22, 2008 8:36 PM by justinsaraceno 


    반응형

    댓글

Designed by Tistory.