ReorderList not deleting item "Index out of range" error.

Last post 04-26-2008 6:44 PM by CraigHoward. 2 replies.

Sort Posts:

  • ReorderList not deleting item "Index out of range" error.

    02-01-2008, 3:55 PM
    • Member
      point Member
    • dsmith1
    • Member since 02-01-2008, 8:47 PM
    • Tupelo, MS
    • Posts 2

    Hi,

     I have a sql data source that is a join from three different tables for the display of information. For the update and delete commands it only has to update one table. The reorder works great. However, the delete command comes back with javascript popup that says:

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

     

    So I tried debugging the page (I am using VWD 2005). I copied the stack trace that was printed out below:
     System.ArgumentOutOfRangeException was unhandled by user code
      Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
      Source="mscorlib"
      ParamName="index"
      StackTrace:
           at System.Collections.ArrayList.get_Item(Int32 index)
           at AjaxControlToolkit.ReorderList.PrepareRowValues(ReorderListCommandEventArgs e, IDictionary& oldValues, IOrderedDictionary& newValues, IDictionary& keys, Boolean isAddOperation) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ReorderList\ReorderList.cs:line 1673
           at AjaxControlToolkit.ReorderList.PrepareRowValues(ReorderListCommandEventArgs e, IDictionary& oldValues, IOrderedDictionary& newValues, IDictionary& keys) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ReorderList\ReorderList.cs:line 1650
           at AjaxControlToolkit.ReorderList.HandleDelete(ReorderListCommandEventArgs e) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ReorderList\ReorderList.cs:line 1397
           at AjaxControlToolkit.ReorderList.OnBubbleEvent(Object source, EventArgs args) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ReorderList\ReorderList.cs:line 1550
           at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
           at AjaxControlToolkit.ReorderListItem.OnBubbleEvent(Object source, EventArgs args) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ReorderList\ReorderListItem.cs:line 138
           at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
           at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
           at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

     

    This appeared to be something in the control to me, but I am relatively new to asp.net and the ajax toolkit. I have searched this forum and several others and do not see any mention of this error, so any help would be appreciated.

     

    Thanks.

    --
    David Smith
  • Re: ReorderList not deleting item "Index out of range" error.

    02-04-2008, 9:17 AM
    • Member
      point Member
    • dsmith1
    • Member since 02-01-2008, 8:47 PM
    • Tupelo, MS
    • Posts 2

    Surely someone has run into this or has a clue as to what has caused this error. Maybe it will help if I post some of my code.

    aspx file:

     

    1    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    2                            <ContentTemplate>
    3                                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:test %>"
    4                                    SelectCommand="select playlists.id, playlists.orderToPlay, artists.artistName, lib.title, lib.buylink ;from artists, lib, playlists where playlists.userid='85ae6f5fa45430cf1f2b3160c1fb9812' and ;(lib.artistId = artists.id) and (playlists.songId = lib.id) order by playlists.orderToPlay asc"
    5                                    UpdateCommand="update playlists set orderToPlay = @orderToPlay where id= @id"
    6                                    DeleteCommand="delete playlists where id= @id">
    7                                    <UpdateParameters>
    8                                        <asp:Parameter Name="orderToPlay" />
    9                                        <asp:Parameter Name="id" />
    10                                   </UpdateParameters>
    11                                   <DeleteParameters>
    12                                       <asp:Parameter Name="id" />
    13                                   </DeleteParameters>
    14                               </asp:SqlDataSource>
    15                               <cc1:ReorderList
    16                                   ID="ReorderList1"
    17                                   CssClass="dragHandle2"
    18                                   runat="server"
    19                                   AllowReorder="True"
    20                                   DataSourceID="SqlDataSource2"
    21                                   PostBackOnReorder="True"
    22                                   SortOrderField="orderToPlay"
    23                                   Width="100%"
    24                                   OnItemCommand="ReorderList1_ItemCommand"
    25                                   >
    26                                   <ItemTemplate>
    27                                   <table width="75%" cellpadding="0" cellspacing="0">
    28                                       <tr>
    29                                           <td align="left" width="2%">
    30                                               <asp:ImageButton ID="ImageButton1" ImageUrl="images/remove.png"
    31                                                   CommandName="Delete" runat="server" />
    32                                           </td>
    33                                           <td align="left" width="6%">
    34                                               <asp:Label ID="lblOrder" runat="server"
    35                                                   Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("orderToPlay"))) %>'></asp:Label>
    36                                           </td>
    37                                           <td align="left" width="41%">
    38                                               <asp:Label ID="lblArtistName" runat="server"
    39                                                   Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("artistName"))) %>'></asp:Label>
    40                                           </td>
    41                                           <td align="left" width="41%">
    42                                               <asp:Label ID="lblTitle" runat="server"
    43                                                   Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("title"))) %>' Width="57px"></asp:Label>
    44                                           </td>
    45                                           <td align="left" width="10%">
    46                                               <div id="buyButton">
    47                                                   <asp:HyperLink ID="hplBuy" runat="server" NavigateUrl='<%# Eval("buyLink") %>'
    48                                                    Target="_blank">
    49                                                       <img src="images/buy.png" border=0 />
    50                                                    <script type="text/javascript">      
    51                                                       link='<%#Eval("buyLink") %>'
    52                                                       //getImg(link);
    53                                                       if(link==""){
    54                                                           HideContent('buyButton');
    55                                                           document.write("<!-- No Link -->");
    56                                                           Sys.WebForms.PageRequestManager.getInstance().add_endRequest(HideContent);
    57                                                       } else {
    58                                                           ShowContent('buyButton');
    59                                                           Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ShowContent);
    60                                                       }                                                    
    61                                                       link = '';
    62                                                    </script>
    63                                                   </asp:HyperLink>
    64                                               </div>
    65                                           </td>
    66                                       </tr>
    67                                   </table>  
    68                                   </ItemTemplate>
    69                                   <DragHandleTemplate>
    70                                       <div class="dragHandle"></div>
    71                                   </DragHandleTemplate>
    72                                   <EditItemTemplate>
    73                                        <br />
    74                                   </EditItemTemplate>
    75                                   <EmptyListTemplate>
    76                                       Please add a song for your playlist.
    77                                   </EmptyListTemplate>
    78                               </cc1:ReorderList>
    79                               <asp:Label ID="lblErrors" runat="server"></asp:Label>
    80                           </ContentTemplate>
    81                       </asp:UpdatePanel>
    
     

     

    aspx.vb file:

     

    1        Protected Sub ReorderList1_ItemCommand(ByVal sender As Object, ByVal e As AjaxControlToolkit.ReorderListCommandEventArgs) Handles ReorderList1.ItemCommand
    2            If e.CommandName = "Delete" Then
    3                Me.ReorderList1.Items.Remove(e.Item)
    4            End If
    5        End Sub
    
     

    Thanks for any input.
     

    --
    David Smith
  • Re: ReorderList not deleting item "Index out of range" error.

    04-26-2008, 6:44 PM
    • Member
      4 point Member
    • CraigHoward
    • Member since 04-25-2008, 6:18 PM
    • Hermon, Maine
    • Posts 7

    DataKeyField needs to be set to the unique identifier of the table you are trying to reorder, update, delete.

    I would also recommend not using ID as your sql field name.  Instead call it something like playlistID.

    In my example below, my unique identifier is called transitionid.

    <cc1:ReorderList ID="ReorderList3" runat="server"
      AllowReorder="True"
      DragHandleAlignment="Left"
      DataSourceID="SqlDataSource3"
      SortOrderField="sortorder"
      PostBackOnReorder="False"
      CssClass="itemArea"
      ItemInsertLocation="End"
      DataKeyField="transitionid">

    <asp:SqlDataSource ID="SqlDataSource3"
      runat="server"      
      ConnectionString="<%$ ConnectionStrings:DiRestaConnectionString %>"
      DeleteCommand="DELETE FROM [Transition] WHERE [transitionid] = @transitionid"
      InsertCommand="INSERT INTO [Transition] ([transition], [sortorder]) VALUES (@transition, @sortorder)"
      SelectCommand="SELECT [transitionid], [transition], [sortorder] FROM [Transition] ORDER BY [sortorder]"
      UpdateCommand="UPDATE [Transition] SET [transition] = @transition, [sortorder] = @sortorder WHERE [transitionid] = @transitionid">
      <DeleteParameters>
      <asp:Parameter Name="transitionid" Type="Int32" />
        </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter Name="transition" Type="String" />
        <asp:Parameter Name="sortorder" Type="Int32" />
        <asp:Parameter Name="transitionid" Type="Int32" />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter Name="transition" Type="String" />
        <asp:Parameter Name="sortorder" Type="Int32" />
      </InsertParameters>
    </asp:SqlDataSource>

     

     

    Craig Howard
    Senior Software Engineer
    Tiger Tech Corporation
Page 1 of 1 (3 items)