HowTo Edit Reorderlist

Last post 03-09-2007 1:38 AM by rtizan. 1 replies.

Sort Posts:

  • HowTo Edit Reorderlist

    09-29-2006, 8:02 PM

    Is there any documentation available on how to use the reorderlist control?  How can I edit items in the control?  What properties do i need to set and what events get fired?  Is there a way to do this without using the objectdatasource or sqldatasource controls?  An example would be appreciated.  Also, does the control maintain the new order of the items in the reorderlist control?

     

  • Re: HowTo Edit Reorderlist

    03-09-2007, 1:38 AM
    • Member
      12 point Member
    • rtizan
    • Member since 01-11-2006, 2:20 AM
    • Posts 4

    I couldn't find any examples that demonstrated edit either. I managed to get it working with a little trial and error (I expect it's obvious to anyone who's familiar with other repeating databound controls - but I'm not).  But just incase it's of use to anybody I attach code below.

    • I found I had to define the DragHandleTemple - otherwise all clicks seem to be captured by the drag feature.
    • I didn't have any luck with a programatically set datasource (just my lack of skill I expect) but  worked fine using an objectDataSource
    • in my case each user has an individual "UserProfile" object and the reorder list is used to edit that user's list of custom links, the details of each link are in linkInfo class that has an id, (display) name, url and a sorOrder.  The object for the objectDataSource is called UserProfileWrapper

    Cheers,

    John

    ==========

    <%@ Page Language="C#" AutoEventWireup="true" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <script runat="server">
      protected void Page_Load(object sender, EventArgs e) {
        UserProfileReference.Value = "xxxxx";
        if (! IsPostBack) {
          DataBind();
        }
      }
    </script>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <title>Untitled Page</title>
    </head>
    <body>
     <form id="form1" runat="server">
      <div>
       <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Select"
        TypeName="Scrap.UserProfileWrapper" UpdateMethod="Update" DeleteMethod="Delete" InsertMethod="Insert">
        <SelectParameters>
         <asp:ControlParameter ControlID="UserProfileReference" Name="userProfileReference"
          PropertyName="Value" Type="String" />
        </SelectParameters>
        <UpdateParameters>
         <asp:ControlParameter ControlID="UserProfileReference" Name="userProfileReference"
          PropertyName="Value" Type="String" />
         <asp:Parameter Name="Id" Type="Int32" />
         <asp:Parameter Name="Name" Type="String" />
         <asp:Parameter Name="Url" Type="String" />
         <asp:Parameter Name="SortOrder" Type="Int32" />
        </UpdateParameters>
        <DeleteParameters>
         <asp:ControlParameter ControlID="UserProfileReference" Name="userProfileReference"
          PropertyName="Value" Type="String" />
         <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
         <asp:ControlParameter ControlID="UserProfileReference" Name="userProfileReference"
          PropertyName="Value" Type="String" />
         <asp:Parameter Name="name" Type="String" />
         <asp:Parameter Name="url" Type="String" />
         <asp:Parameter Name="SortOrder" Type="Int32" />
        </InsertParameters>
       </asp:ObjectDataSource>
      </div>
      <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1">
      </asp:GridView>
      <asp:HiddenField ID="UserProfileReference" runat="server" />
      <asp:ScriptManager ID="ScriptManager1" runat="server">
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
       <ContentTemplate>
        <cc1:ReorderList ID="Reorder" runat="server" AllowReorder="True" DataSourceID="ObjectDataSource1"
         PostBackOnReorder="False" SortOrderField="SortOrder" DataKeyField="Id" ItemInsertLocation="End">
         <DragHandleTemplate>
          X_DragHandle_X</DragHandleTemplate>
         <ItemTemplate>
          <div class="itemArea">
           &nbsp;&nbsp;<asp:LinkButton ID="ItemEdit" CommandName="edit" runat="server">Edit</asp:LinkButton>
           &nbsp;&nbsp;<asp:LinkButton ID="ItemDelete" CommandName="delete" runat="server">Delete</asp:LinkButton>
           <asp:Label ID="Label1" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Name"))) %>' />
           <asp:Label ID="Label2" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Url", " - {0}"))) %>' />
          </div>
         </ItemTemplate>
         <EditItemTemplate>
          <div class="itemArea">
           <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Name") %>' />
           <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Url") %>' />
           <asp:LinkButton ID="EditUpdate" runat="server" CommandName="Update">Save</asp:LinkButton>
           <asp:LinkButton ID="EditCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
          </div>
         </EditItemTemplate>
         <InsertItemTemplate>
          <div class="itemArea">
           <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Name") %>' />
           <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Url") %>' />
           <asp:LinkButton ID="Insert" runat="server" CommandName="Insert">Insert</asp:LinkButton>      
          </div>      
         </InsertItemTemplate>
        </cc1:ReorderList>
       </ContentTemplate>
      </asp:UpdatePanel>
     </form>
    </body>
    </html>


    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    source object for objectDataSource:

      public class UserProfileWrapper
      {
        public UserProfileWrapper() {
        }

        GetUserProfile(string userProfileReference){
            //custom code here (uses a static function elsewhere to get the user's UserProfile)
        }

        public LinkInfo[] Select(string userProfileReference) {
         //custom code here
        }

        public void Update(string userProfileReference, int id, string name, string url, int sortOrder) {
         //custom code here
        }

        public void Insert(string userProfileReference, string name, string url, int sortOrder) {
         //custom code here
        }

        public void Delete(string userProfileReference, int id) {
         //custom code here
        }
      }

    O what a world of profit and delight,
    Of power, of honor, of omnipotence,
    Is promised to the studious artisan !
Page 1 of 1 (2 items)