2012年3月28日水曜日

Resortlist doesnt update datasource

Hi,

I have a problem with resortlist that makes me mad :-)

I want to bind an ObjectDataSource or a SQLDataSource to a reorderlist, which both works fine when loading data into a itemlist. I can drag and drop all items - but whatever I do, the changed position of my list items won't be saved, neither to the ODS nor the SQLDatasource. Btw: Actually I use the Control Toolkit released mid December and AJAX RC 1. Any idea what's going wrong?


1 <asp:SqlDataSource ID="SQLDataSource1" runat="server"2 ConnectionString="(...)"3 SelectCommand="SELECT [ID], [Name1], [Name2], [order] FROM [tbl_orderlist]"4 UpdateCommand="UPDATE [tbl_orderlist] SET [order]=@dotnet.itags.org.order WHERE [ID]=@dotnet.itags.org.ID">5 <UpdateParameters>6 <asp:Parameter Name="ID" Type=int32 />7 <asp:Parameter Name="order" Type="int32" />8 </UpdateParameters>9 </asp:SqlDataSource>1011 <ajaxToolkit:ReorderList ID="ReorderList1" runat="server"12 DataSourceID="SQLDataSource1"13 ShowInsertItem="true"14 LayoutType="Table"15 DragHandleAlignment="Left"16 DataKeyField="ID"17 AllowReorder="true"18 SortOrderField="order"19 PostBackOnReorder="true"20 CssClass="keyword" >2122 <DragHandleTemplate>23 <div class="dragHandle">24 <table border="0" cellspacing="0" cellpadding="0">25 <tr>26 <td valign="top" class="moveitem"><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name1")%>' /></td>27 <td valign="top" class="moveitem"><asp:Label ID="Label2" runat="server" Text='<%# Eval("Name2")%>' /></td>28 </tr>29 </table>30 </div>31 </DragHandleTemplate>32 </ajaxToolkit:ReorderList>

Thanx a lot for every hint!Smile

Join the club...

I'm fighting the same battle, and it's driving me nuts! The update command simply refuses to fire. I had it working, and now it doesn't work. I just can't seem to get the event to fire.

What happens when you set PostBackOnReorder="false"?


I'm experiencing the same problem! And have no idea what to do... Could anyone from Microsoft Team comment this situation?

Any ideas??


Same problem here!!!! It seems like a bug inside the Reorderlist. Any help here?

Try this site:http://www.codeplex.com/AtlasControlToolkit

In my case, I put a TextBox inside <EditItemTemplate> and binded it to the column in the DB that needs to be updated when reordering:

<EditItemTemplate> <asp:TextBox ID="txtItemOrder" runat="server" Text='<%# Bind("ItemOrder")%>' /></EditItemTemplate>

has anyone figured this out yet?!?!? and does anyone know where I can download the actual code from the AJAX sample website so I can have a look at how MS implemented this?
Driving me crazy!!!


Could you please post the code that actually handles the updateproces for you? So the code-behind method and your datasource/reorderlist definition?

Thanks ahead!


I basically just copied the actual code from the AJAX sample website and tweaked that. I also didn't use any code-behind to handle the reordering. Here's the code:

1<asp:UpdatePanel ID="up1" runat="server">2 <ContentTemplate>3 <div class="reorderListDemo">4 <ajaxToolkit:ReorderList ID="ReorderList1" runat="server" Width="780px" PostBackOnReorder="true"5 DataSourceID="ReorderDataSource" CallbackCssStyle="callbackStyle" DragHandleAlignment="Left"6 ItemInsertLocation="Beginning" DataKeyField="Item_ID" SortOrderField="ItemOrder" CssClass="reorderList">7 <ItemTemplate>8 <div class="itemArea">9 <asp:Label ID="lblItemOrder" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("ItemOrder")))%>' />10 <asp:Label ID="lblName1" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Name1", " - {0}")))%>' />11 <asp:Label ID="lblName2" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Name2", " - {0}")))%>' />12 </div>13 </ItemTemplate>14 <EditItemTemplate>15 <div class="itemArea">16 <asp:TextBox ID="txtItemOrder" runat="server" Text='<%# Bind("ItemOrder")%>' ValidationGroup="edit" />17 </div>18 </EditItemTemplate>19 <ReorderTemplate>20 <asp:Panel ID="Panel2" runat="server" CssClass="reorderCue" />21 </ReorderTemplate>22 <DragHandleTemplate>23 <div class="dragHandle"></div>24 </DragHandleTemplate>25 </ajaxToolkit:ReorderList>26 </div>27 </ContentTemplate>28</asp:UpdatePanel>2930<asp:SqlDataSource ID="ReorderDataSource" runat="server" ConnectionString="<%$ ...%>"31 SelectCommand="SELECT [Item_ID], [Name1], [Name2], [ItemOrder] FROM [Table1]"32 UpdateCommand="UPDATE [Table1] SET [ItemOrder]=@.ItemOrder WHERE Item_ID=@.Item_ID">33 <UpdateParameters>34 <asp:Parameter Name="ItemOrder" Type="Int32" />35 </UpdateParameters>36</asp:SqlDataSource>37

hmm..in your updatecommand you use the parameter @.item_ID...wherefrom is this retreived?

Also, when you reorder items shouldnt there always be 2 items updated? if item 1 goes to index 2, item 2 should go to index 1 right? I dont see how that happens here...

Help is appreciated!

Ok, I now have this, but its still not working...what am I missing here?

<cc1:ReorderList PostBackOnReorder="true"
SortOrderField="RuleIndex"
ID="rolRules"
AllowReorder="true"
DataKeyField="RuleID"
DataSourceID="ReorderDataSource"
runat="server">
<ItemTemplate>
<%#Eval("RuleIndex")%>
<%#Eval("RuleName")%>
</ItemTemplate>
</cc1:ReorderList>

<asp:SqlDataSource ID="ReorderDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SQLAuth %>"
SelectCommand="SELECT RuleID,RuleName,ruleindex FROM myRules WHERE UserCode=@.UserCode"
UpdateCommand="UPDATE myRules SET RuleIndex=@.RuleIndex WHERE RuleID=@.RuleID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="id" Name="UserCode" Type="int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="RuleIndex" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>


myRules table structure:
RuleID int
RuleName nvarchar(20)
ruleindex tinyint
<and some other fields
Thanks!


Peter Smith:

hmm..in your updatecommand you use the parameter @.item_ID...wherefrom is this retreived?

That Item_ID is referenced by the DataKeyField property of the ReorderList (similar with GridView), retrieved from the SELECT command in the DataSource.

Peter Smith:

Also, when you reorder items shouldnt there always be 2 items updated? if item 1 goes to index 2, item 2 should go to index 1 right? I dont see how that happens here...

Help is appreciated!

Well, I guess that's the beauty of the ReorderList control - it does the dirty work for us. As long as we declare which field from the SELECT command is the identity column, and the field that needs resorting... the control handles the rest. We'd have to look at the source code of ReorderList control in order to truly understand the inner workings of how it keeps track of which index should go to another index (etc).Smile But my guess is that, this is done using ViewState to "remember" the values (Identity column, and ItemOrder), and through Javascript's mouse event handlers which triggers the saving of the values to executing the UPDATE command in the DataSource. This is just my personal idea.

I am using AJAX Control Toolkit release 10301 (2007-03-01) and it worked for me using the code I posted here.(Quick note: I experimented with ReorderList again, and found out that using <EditItemTemplate> is not necessary to make the reordering mechanism work; so what I initially said in my first post in this thread doesn't apply anymore).

Best regards!


Peter Smith:

Ok, I now have this, but its still not working...what am I missing here?

Peter,

at first glance, your code looks fine. However, what caught my attention is the "cc1:" tag prefix for the ReorderList control. If the latest version of the AJAX Control Toolkit is correctly installed and registered, the tag prefix should normally be "ajaxToolkit:". So, you might first verify your correct installation of the CT.


che_rish:


Peter Smith:

Also, when you reorder items shouldnt there always be 2 items updated? if item 1 goes to index 2, item 2 should go to index 1 right? I dont see how that happens here...

Well, I guess that's the beauty of the ReorderList control - it does the dirty work for us. As long as we declare which field from the SELECT command is the identity column, and the field that needs resorting... the control handles the rest.

Just in addition to che_rish's excellent explanation: Note that it's not just about swappingtwo ItemOrder values... :) Actually, dragging an item to a different position can comprise as much as updating the ItemOrder fields ofevery single row in the list (for example, when dragging the last item to the first position. And yes, it's all done in the client-side JavaScript that comes with the ReorderList control.Smile


I also used same coding like u. I am also facing same problem.. If any resolves this just let me know.. Thank U.

0 件のコメント:

コメントを投稿