ReOrderList Example AJAX.NET Toolkit

5. May 2008

Again I wanted to use an AJAX Toolkit item and the example Microsoft provided fell a bit short.  Even the example that came with the AJAXToolkit Web Pages still wasn't fully developed. They left out on how to properly edit and update an item in the ReOrderList.  In addition they used an ObjectDataSource and I don't use those very often.

I wanted to provide a full example of the ReOrderList that shows how to read, add, update, and delete items from the ReOrder list using a SQLDataSource instead of the ObjectDataSource Microsoft Provided.  Please ignore the actually looks of this example as I didn't spend any time styling it with CSS.  This just provides the functionality.

First I created a test table in my local SQL Database called TestTable1.  The columns included are the following:

 - intID (primary with identity enabled)
 - strName
 - strLink
 - intOrder (for order of list items)

Next I coded up the ReOrder List page.  I didn't use any code behind so I'm just pasting what the markup aspx page looks like.

The one item I was wondering about the most was how to actually wire up the Edit, Update, Delete, and Cancel commands to the list. Since I was using a SqlDataSource this actually was very easy. You just need to add the attribute CommandName="" to a LinkButton or Button. For example if I want to activate the EditItemTemplate you'll notice the link button in the ItemTemplate with the attribute CommandName="Edit".

Then you'll notice in the EditItemTemplate to properly edit the item, for Text attribute is '<%# Bind("yourColumn") %>'. This will handle editing back to the database on its own.  You'll also notice the same method for the Text attribute for the TextBoxes in the InsertItemTemplate.

Well again I'm showing this because the example from Microsoft left out the Edit, Update and Delete portions...and didn't use a SqlDataSource that the ReOrder list could bind too.

As always any problem with the code let me know so I can update this post, but I was just using this.

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

AJAX.NET ,

Comments

5/5/2008 8:09:38 PM #
Trackback from DotNetKicks.com

ReOrderList Full Example
Tommy
5/12/2008 2:16:03 PM #
Thanks, mate. I've it working but still do not understand why previously, when I tried to do it myself got the exception: "...It's not a datasource and does not implement IList". Can you give some light on it?
John_M
5/13/2008 3:53:15 AM #
Hey Tommy,  Were you doing an object datasource? If so the object would have to be setup correctly?
8/7/2008 12:24:32 PM #
How to dynamically change the select query? by different where condititon. i have tried through code behind but im getting thsi error.

---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
System.NullReferenceException: Object reference not set to an instance of an object.

   at AjaxControlToolkit.ReorderList.DoReorderInternal(IEnumerable dataSource, Int32 oldIndex, Int32 newIndex, DataSourceView dsv) in C:\Documents and Settings\USER\Desktop\AjaxControlToolkit\AjaxControlToolkit\ReorderList\ReorderList.cs:line 1037

   at AjaxControlToolkit.ReorderList.<>c__DisplayClass4.<DoReorder>b__0(IEnumerable dataSource) in C:\Documents and Settings\USER\Desktop\AjaxControlToolkit\AjaxControlToolkit\ReorderList\ReorderList.cs:line 903

   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)

   at AjaxControlToolkit.ReorderList.DoReorder(Int32 oldIndex, Int32 newIndex) in C:\Documents and Settings\USER\Desktop\AjaxControlToolkit\AjaxControlToolkit\ReorderList\ReorderList.cs:line 916

   at AjaxControlToolkit.ReorderList.OnItemReorder(ReorderListItemReorderEventArgs e) in C:\Documents and Settings\USER\Desktop\AjaxControlToolkit\AjaxControl......

<truncated>
---------------------------
Abort   Retry   Ignore  
---------------------------

rgrds
Kanna..
Mike
11/2/2008 11:12:24 AM #
Thank you so much!!  I've been kicking myself trying to figure out how to make this control work, and the examples I've been finding weren't quite doing it.

Yours did and I am VERY grateful!

Thanks,
Mike
4/24/2009 8:00:58 PM #
This is so helpful. That you so much for putting together a very simple, but fully functional example. I find the Sample code for the Ajax Toolkit frustrating because it is done in such a way that it is easy to author the examples, but difficult to extract the details needed to implement outside of the application. Your example is so easy to use! Thank you!

Brent
4/25/2009 6:04:08 PM #
Brent thanks for the comment, I found the examples on the ajax toolkit site the same exact way!
chihying
6/1/2009 11:53:41 AM #
Great example, Thank you.
Was struggling with ObjectDataSource but no good example out there. Your post saved my time.
Your example should be added to official AJAX tutorial.  
Alecia
7/21/2009 8:31:10 PM #
Thank you so much - your example has saved me a huge amount of frustration.  One problem I am still having is that the intOrder is being saved to Null when inserting an item.  Having to create workaround since Max(intOrder) is not allowed in my selects.....

Alecia
debaish
10/11/2009 12:50:47 AM #
Thx dude this is wat i was looking for,Grt help man,Thx again
Tony
10/13/2009 11:23:50 PM #
I have done exactly what you have done, but it doesnt update the database.

My db structure is...
ID          int  
Category  nvarchar(255)
MenuOrder  float

<ajaxToolkit:ReorderList ID="ReorderList1" runat="server"
                    AllowReorder="True"
                    PostBackOnReorder="False"
                    SortOrderField="MenuOrder"
                    DataKeyField="ID"
                    DataSourceID="SqlDataSource1"
                    ItemInsertLocation="End">
                        <ItemTemplate>
                            &nbsp;
                             <asp:Label  ID="HyperLink1" runat="server" Text='<% #Eval("Category") %>' />
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
                            <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Delete" Text="Delete" />
                        </ItemTemplate>
                        <DragHandleTemplate>
                            <div style="height: 20px; width: 20px; border: solid 1px black; background-color: Red; cursor: pointer;">
                                &nbsp;
                            </div>
                        </DragHandleTemplate>
                        <ReorderTemplate>
                            <div style="width: 300px; height: 20px; border: dotted 2px black;">
                                &nbsp;
                            </div>
                        </ReorderTemplate>
                    </ajaxToolkit:ReorderList>

<asp:SqlDataSource ID="SqlDataSource1"
    runat="server"
    ConnectionString="Data Source=WEBDEVEL1\SQLEXPRESS;Initial Catalog=WPD;Integrated Security=True"
    DeleteCommand="DELETE FROM [tblCategories] WHERE [ID] = @ID"
    InsertCommand="INSERT INTO [tblCategories] ([Category], [MenuOrder]) VALUES (@Category, @MenuOrder)"
    ProviderName="System.Data.SqlClient"
    SelectCommand="SELECT * FROM [tblCategories]"
    UpdateCommand="UPDATE [tblCategories] SET [Category] = @Category, [MenuOrder] = @MenuOrder WHERE [ID] = @ID">
    <DeleteParameters>
      <aspTongarameter Name="ID" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
      <aspTongarameter Name="Category" Type="String" />
      <aspTongarameter Name="MenuOrder" Type="Double" />
      <aspTongarameter Name="ID" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
      <aspTongarameter Name="Category" Type="String" />
      <aspTongarameter Name="MenuOrder" Type="Double" />
    </InsertParameters>
  </asp:SqlDataSource>

dnn
10/22/2009 7:45:43 PM #
Hi,

I wonder if you could lendme a help here.
I use a ReorderList that binds to a SqlDataSource (RouteId, RouteName, TruckId, ListingOrder). In <InsertItemTemplate>, I use a <aspLaughingropDownList> that binds to another SqlDataSource (TruckId & TruckName).  How I can add a new item to the list from a dropdownlist?
. routeA (textboxRoute)   |     truck4   (dropdownlistTruck)
. routeB                  |     truck3
-->insert routeC          |     truck1 ???

I tried asp:ControlParameter with Control="dropdownlistTruck" PropertyName="SelectedValue" but it does not recognize dropdownlistTruck

Thank you,


dnn
mahi
11/5/2009 10:50:15 PM #
Hi friends,
I got a QQ on AJAX Reorderlist Itemtemplate.
I am using two reorderlist controls with in a page.
Reorderlis1 contains pending records. I just load the  pending records. the records can be moved from  Reorderlist 1 to Reordrlist 2 with add button. In this table I am not doing reordering
Reorderlist2 contains Queued records. In this I will do the reordering, the records which are there in Reorderlist 2 , transfer the records into the tasktable. In this table I have the cancel button also. If user don’t want to update some records they can moved back those records from Recorder list 2 to Recorderlist 1.
I am done with this part.
My 1st QQ:
Now I added Dropdownlist control to the Reorderlist 1  Item tamplate. Item template dropddownlist is my user control.My dropdown list contains the list of years.
So I am calling my Usercontrol method with the Itrmtamplate dropdownlist ID. Here I got below error. 'ddlbeginyod1' is my Reorderlist Item template dropdownlist ID Text.
Why??
Error:The name 'ddlbeginyod1' does not exist in the current context.
I tried adding the dropdownlist in insertitem template also. There also I got the same issue.
I never worked with Ajax Reorderlist control. I  am very confused with this control.

I can add Dropdown list to the Reordrlist Itemtamplate right ?
If I can add the dropdownlist into the item template I have 2nd QQ?
•  If I can  load the dropdownlist. For each row I will be having the year dropdownlist right.
When user selects first row and moved  from the reorderlist1 to reorderlist 2 with add button. he has to select the year of that row. I need to send year value by each row to task table. Can I  do that with reorderlist item template.How can I store the year value.If so, how can I do that?
Please any one know the answer ,,please suggest me …
11/6/2009 4:29:36 PM #
Mahi, I'm going to take a shot here as some of your comment was a bit unclear to me. Sounds like the first problem you are having is the dropdown list in the item template.  I haven't tested this, but I don't see any issue with a drop down list in the item template.  However, I would see an issue with binding the drop down list in the item template.  Are you binding the drop down list to any specific data source.  If so you will have to do one of two things.  You would have the find the control on the item databound, or row databound event, and populate it that way. Or you would have to set the datasource in the markup to something like DataSource='<%# mypublicfunction.SetData() %>' within set data you can return a dataset or any object that will bind to the drop down liast.  

As far as sending the year back...on your commit/save you would need to loop through each item in the reorderlist and cast a control as the dropdown list as such:

DropDownList myDDL = (DropDownList)myReorder.Items[i].FindControl("yourDDLName");
string year = myDDL.SelectedValue;

Don't hold me to any of this since it's early here in Arizona Smile  But this should get you on the right track. I apologize for not having more time to put some tested code on here.  Good luck

John M
rasha
11/10/2009 12:55:41 PM #
hi,
i still has the same error "It's not a datasource and does not implement IList", am i missing something ?? i did exactly what you did , so what is the problem?
ken
12/3/2009 5:08:05 PM #
This is a great working example. Just substitute your db info for his and walla.
Thanks
Ken
Mital
1/19/2010 3:23:12 PM #
Hi John,
This post was really useful for me...
I want one help can you post the example with dropdownlist in InsertItemTemplate EditItemTemplate and Itemtemplate...

Thanks in Advance

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading