This is a migrated thread and some comments may be shown as answers.
a simple way in the server side to get all items in the ListBox after they have been reorder by the user (either by the up down arrows or drag and d
1 Answer 3 Views
This is a migrated thread and some comments may be shown as answers.
Hagai
Top achievements
Rank 1
Hagai asked on 13 May 2020, 10:20 AM

Hi,

 

Is there a simple way in the server side  to get all items in the ListBox after they have been reorder by the user (either by the up down arrows or drag and drop)?

I have a save button which when the user click on it i need to get the items in the ListBox so i can update the indexes of the items in my model.

currently i tired that:

 

001.
//this is the clas model
 public class Publication : DataContractClass
002.    {
003.        public enum LanguageName
004.        {
005.            Hebrew,
006.            English
007.        }
008.  
009.        [DataMember]
010.        private long id;
011.        public long Id
012.        {
013.            get { return id; }
014.            set { id = value; }
015.        }
016. 
017.        [DataMember]
018.        private LanguageName language;
019.        public LanguageName Language
020.        {
021.            get { return language; }
022.            set { language = value; }
023.        }
024. 
025.        [DataMember]
026.        private string text;
027.        public string Text
028.        {
029.            get { return text; }
030.            set { text = value; }
031.        }
032. 
033.        [DataMember]
034.        private int index;
035.        public int Index
036.        {
037.            get { return index; }
038.            set { index = value; }
039.        }
040. 
041.        [DataMember]
042.        private string link;
043.        public string Link
044.        {
045.            get { return link; }
046.            set { link = value; }
047.        }
048. 
049.        [DataMember]
050.        private long fileId;
051.        public long FileId
052.        {
053.            get { return fileId; }
054.            set { fileId = value; }
055.        }
056. 
057.        [DataMember]
058.        private byte[] publicationBlob;
059.        public byte[] PublicationBlob
060.        {
061.            get { return publicationBlob;  }
062.            set { publicationBlob = value; }
063.        }
064. 
065.        [DataMember]
066.        private bool isDeleted;
067.        public bool IsDeleted
068.        {
069.            get { return isDeleted; }
070.            set { isDeleted = value; }
071.        }
072. 
073.        [DataMember]
074.        private bool isSelected;
075.        /// <summary>
076.        /// Gets or sets a value indicating whether this publication is selected publication.
077.        /// </summary>
078.        /// <value>
079.        ///     <c>true</c> if this publication is selected; otherwise, <c>false</c>.
080.        /// </value>
081.        public bool IsSelected
082.        {
083.            get { return isSelected; }
084.            set { isSelected = value; }
085.        }
086. 
087.        [DataMember]
088.        private bool hasPublication;
089.        public bool HasPublication
090.        {
091.            get { return hasPublication; }
092.            set { hasPublication = value; }
093.        }
094.    }
095.

//this is my property in my webform

096.static List<Publication> FacultyPublications
097.        {
098.            get
099.            {
100.                string sessionKey = $"FacultyPublications_{FacultyUserName}";
101.                if (HttpContext.Current.Session[sessionKey] != null)
102.                {
103.                    return (List<Publication>)HttpContext.Current.Session[sessionKey];
104.                }
105.                else
106.                {
107.                    return null;
108.                }
109.            }
110.            set
111.            {
112.                string sessionKey = $"FacultyPublications_{FacultyUserName}";
113.                HttpContext.Current.Session[sessionKey] = value;
114.            }
115.        }
116.//this is my save button event
117.protected void RadButtonSavePublicationsOrder_Click(object sender, EventArgs e)
118.        {
119.            foreach (Publication pub in FacultyPublications)
120.            {
121.                pub.Index = RadListBoxPublications.FindItemIndexByValue(pub.Id.ToString());
122.            }
123.            XDocument document = new XDocument(new XElement("Root",
124.                from pub in FacultyPublications
125.                select
126.                new XElement("Publication",
127.                    new XElement("PublicationID", pub.Id),
128.                    new XElement("SortIndex", pub.Index))
129.                ));
130. 
131.            if (appDal.UpdatePublicationsIndexes(FacultyUserName, CurrentUserName, document.ToString()))
132.            {
133.                BindPublications();
134.                RadWindowManagerPublications.RadAlert(GetLocalString("msgSuccessAction"), 600, 200, string.Empty, string.Empty);
135.            }
136.            else
137.            {
138.                //failed
139.                RadWindowManagerPublications.RadAlert(GetLocalString("msgNotSuccessAction"), 600, 200, string.Empty, string.Empty);
140.                return;
141.            }
142.        }
143.    }

 

and here is the radlistbox declaration

01.<telerik:RadListBox ID="RadListBoxPublications" runat="server" AllowReorder="True" EnableDragAndDrop="True" Width="98%" Height="700px" AutoPostBackOnReorder="true">
02.            <HeaderTemplate>
03.                <div class="row">
04.                    <div class="col-md-9">
05.                        <h4>
06.                            <asp:Literal runat="server" Text="<%$ Resources:FacultySites, PublicationsTitle%>"></asp:Literal>
07.                        </h4>
08.                    </div>                   
09.                    <div class="col-md-2">
10.                        <div class="row">
11.                            <div class="col-md-5">
12.                                <%--<asp:Literal runat="server" Text="<%$ Resources:FacultySites, Edit%>"></asp:Literal>--%>
13.                                <telerik:RadButton ID="RadButtonAddNewPublication" runat="server" RenderMode="Lightweight" ToolTip="<%$ Resources:FacultySites, AddNewPublication%>" OnClick="RadButtonAddNewPublication_Click">
14.                                    <ContentTemplate>
15.                                        <span class="glyphicon glyphicon-edit"></span> <asp:Literal runat="server" Text="<%$ Resources:FacultySites, AddNewPublication%>"></asp:Literal>
16.                                    </ContentTemplate>
17.                                </telerik:RadButton>
18.                            </div>                           
19.                            <div class="col-md-7">
20.                                                                 
21.                                <telerik:RadButton ID="RadButtonSavePublicationsOrder" runat="server" RenderMode="Lightweight" ToolTip="<%$ Resources:FacultySites, SavePublicationsOrder%>" OnClick="RadButtonSavePublicationsOrder_Click">
22.                                    <ContentTemplate>
23.                                        <span class="glyphicon glyphicon-save"></span> <asp:Literal runat="server" Text="<%$ Resources:FacultySites, SavePublicationsOrder%>"></asp:Literal>
24.                                    </ContentTemplate>
25.                                </telerik:RadButton>                                                               
26.                            </div>
27.                        </div>
28.                    </div>
29.                    <div class="col-md-1"> </div>
30.                </div>
31.            </HeaderTemplate>
32.            <ItemTemplate>
33.                <div class="row">
34.                    <div class="col-md-9">
35.                        <div dir="<%# (DataBinder.GetDataItem(Container) as Idc.FacultySites.Models.Publication).Language == Idc.FacultySites.Models.Publication.LanguageName.Hebrew? "rtl" : "ltr" %>"
36.                            class="<%# (DataBinder.GetDataItem(Container) as Idc.FacultySites.Models.Publication).Language == Idc.FacultySites.Models.Publication.LanguageName.Hebrew? "text-right-fix" : "text-left-fix" %>">
37.                            <a id="PublicationLink" runat="server">
38.                                <%# (DataBinder.GetDataItem(Container) as Idc.FacultySites.Models.Publication).Text %>
39.                            </a>
40.                        </div>
41.                    </div>
42.                    <div class="col-md-1"> </div>
43.                    <div class="col-md-2">
44.                        <div class="row">
45.                            <div class="col-md-2">
46.                                <telerik:RadButton ID="RadButtonEditPublication" runat="server" RenderMode="Lightweight" ToolTip="<%$ Resources:FacultySites, Edit%>" CommandArgument="<%# (DataBinder.GetDataItem(Container) as Idc.FacultySites.Models.Publication).Id %>" OnCommand="RadButtonEditPublication_Command">
47.                                    <ContentTemplate>
48.                                        <span class="glyphicon glyphicon-edit"></span>
49.                                    </ContentTemplate>
50.                                </telerik:RadButton>
51.                            </div>
52.                            <div class="col-md-2">
53.                                <telerik:RadButton ID="RadButtonDeletePublication" runat="server" RenderMode="Lightweight" ToolTip="<%$ Resources:FacultySites, Delete%>" OnClick="RadButtonDeletePublication_Click" CommandArgument="<%# (DataBinder.GetDataItem(Container) as Idc.FacultySites.Models.Publication).Id %>" OnCommand="RadButtonDeletePublication_Command">
54.                                    <ContentTemplate>
55.                                        <span class="glyphicon glyphicon-remove"></span>
56.                                    </ContentTemplate>
57.                                    <ConfirmSettings ConfirmText="<%$ Resources:FacultySites, GeneralActionConfirmMessage%>" />
58.                                </telerik:RadButton>
59.                            </div>
60.                            <div class="col-md-8"> </div>
61.                        </div>
62.                    </div>
63.                </div>
64.                <div class="row">
65.                    <div class="col-md-12"> </div>
66.                </div>
67.            </ItemTemplate>
68.        </telerik:RadListBox>

 

but it's not working and I keep getting the ListBox items as they have been in the first time I load them from the db.

 

Looking forward to an earliest reply and help

Thanks.

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 18 May 2020, 11:45 AM

Hello Hagai,

The OnReordered event has the information on the items that will be reordered and the Listbox has the items in the new order. Please check if that would fit your scenario:

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Asked by
Hagai
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or