views:

16

answers:

0

I'm trying to implement .sortable on a ListView, with a few problems.

Using this event I save the order of the elements:

$('#sortable').bind("sortupdate", function (event, ui) {
    var array = $('#sortable').sortable("toArray");
        $.ajax({
            type: "POST",
            url: "../Resources/WebServices/MailTemplateCategory.asmx/MoveCategory",
            data: "{ 'array' : '" + array + "' }",
            contentType: "application/json; charset=utf-8",
        });
    });
}
</script>

But after moving one item, and trying to edit another, the EditTemplate appears on the items previous position (If it's been pushed down due to movement of other item), I'm guessing due to the way the ListView and EditIndex works?

My ListView is set up like this:

<asp:ListView ID="myListView" runat="server" DataSourceID="myOds">
    <LayoutTemplate>
        <ul id="sortable">
            <li id="ItemPlaceholder" runat="server"></li>
        </ul>
    </LayoutTemplate>
    <ItemTemplate>
        <li id='<%# Eval("ID") %>'>
            <table>
                <tr>
                    <td><div class="ui-handle"></div></td>
                    <td><asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label></td>
                    <td><asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" ></asp:LinkButton></td>
                </tr>
            </table>
        </li>
    </ItemTemplate>
    <EditItemTemplate>
        <li>
            <table>
                <tr>
                    <td><div class="ui-handle"></div></td>
                    <td><asp:TextBox runat="server" ID="tbName" Text='<%# Bind("Name") %>'></asp:TextBox></td>
                    <td><asp:LinkButton ID="btnSave" runat="server" Text="Save" CommandName="Update" ></asp:LinkButton></td>
                </tr>
            </table>
        </li>
    </EditItemTemplate>
    <EmptyDataTemplate>
         Could not find any items.
    </EmptyDataTemplate>
</asp:ListView>

The ListView is populated by an ObjectDataSource. Editing and saving works, it's just that it triggers the editing on the wrong item in the ListView. Edit: Forgot to mention, it's wrapped in an UpdatePanel.

My question is. Is there any way to update the EditIndex on the ListView? (If what I've assumed is the actual problem)