This is a migrated thread and some comments may be shown as answers.

Inconsistent results

6 Answers 100 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 2
Joshua asked on 03 May 2010, 09:56 PM
Hello,
I have two list boxes (radFullList and radList) which are linked together for AllowTransfer. Not that it matters but the first listbox is a list of employee names, the value is their employee number. The second listbox is for holding the employee's supervisors so when you move an items from radFullList to radList it maintains the same format, employee name and employee number in the value.

EmployeeEditView.ascx
<telerik:RadListBox ID="radFullList" runat="server" AllowTransfer="True"  
    AllowTransferOnDoubleClick="true" EnableDragAndDrop="true" TransferToID="radList"  
    DataKeyField="GUID" DataSortField="EmployeeName" DataSourceID="LinqDS4"  
    DataTextField="EmployeeName" DataValueField="EmployeeNumber" Height="200px"  
    Width="200px"
    <ButtonSettings ReorderButtons="Common"></ButtonSettings> 
</telerik:RadListBox> 
<telerik:radlistbox ID="radList" runat="server" Height="200px" Width="200px"  
    AllowReorder="true" AllowDelete="true" /> 
<asp:LinqDataSource ID="LinqDS4" runat="server"  
    ContextTypeName="Modules.EmployeeManagement.EmployeeManagementDataContext"  
    TableName="tblEmployees" OrderBy="EmployeeName" > 
</asp:LinqDataSource> 

I have this wired up to a Save button in my Sitefinity Module. 

EmployeeEditView.ascx.vb
Dim sb As New StringBuilder() 
Dim db = New Modules.EmployeeManagement.EmployeeManagementDataContext 
Dim employee = (From t In db.tblEmployees Where t.GUID = Me.DataItemId Select t).Single 
employee.EmployeeNametxtName.Text 
... 
employee.UserGroup = radUserGroup.SelectedValue 
For Each item As RadListBoxItem In radList.Items 
    sb.Append(item.Value.ToString & "|") 
Next 
employee.SupervisorNumber = Left(sb.ToString, 59) 
db.SubmitChanges() 
Response.Redirect(CreateHostViewCommand("EmployeeEditView", DataItemId.ToString, Nothing)) 

So as you can see all I am doing is a simple write from the form.

Scenario: This code works perfectly if the second listbox (radList) is empty. You add 1 or 2 employees to the second list box, hit save and the results written to the database are accurate.

If you go back in to this employee's account, you will see everything is correct. Instead of exiting, if you simply hit Save again all the entries in the second listbox, radList, are duplicated. Both times the same code is used since I am "Updating" the employee both times.

As a test to get screens for this post I edited an employee who has no supervisors. Which you can see in screenshot "001.png". Screenshot "002.png" is after adding two accounts as supervisors. The screenshot is taken after Save is clicked which means not only did it save to the database correctly, but it was loaded into the listbox correctly as well. Now in screenshot "003.png" is after clicking the Save button once more without performing any work with the listboxes. As you can see the two entries are repeated.

As far as I can tell from looking up documentation associated with RadListBox I am using the correct code to cycle through items. "For Each item As RadListBoxItem In radList.Items" Any help you can offer would be greatly appreciated.

6 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 05 May 2010, 04:45 PM
Hi Joshua,

This is interesting behavior. Do you use AJAX? Please make sure that the destination RadListBox is correctly updated by the AJAX call.  Also, where does the Response.Redirect statement redirects to, what happens if you comment it out? Further, which is the version of the controls that you use?

Sincerely yours,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Joshua
Top achievements
Rank 2
answered on 12 May 2010, 02:13 AM
No I am not using AJAX. I simply process the contents of the second ListBox onSubmit.

The Response.Redirect redirects to a View in a SiteFinity Module. Technically all it does is refresh the current page since this is the same View. By redirecting to the same View and passing in the GUID of the current record I am verifying that the changes we submitted did in face write out. This also gives the user the ability to update something else at the same time, or cancel and go back to the grid.

I have commented out the Redirect with the same results.
0
Genady Sergeev
Telerik team
answered on 14 May 2010, 02:46 PM
Hi Joshua,

This is interesting, can you try the following, after hitting save for the first time check the client state of the destination RadListBoxItem. This can be achieved with a tool like firebug. Select on the RadListBox body with the select pointer and check the client state. Please refer to the sceenshots attached for details.

Further, do you have any codebehind lines that rebind the destination RadListBox? Or any lines at all connected with DataBinding the RadListBoxes?

Best wishes,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Joshua
Top achievements
Rank 2
answered on 20 May 2010, 06:47 PM
I believe I have what you are asking for with Firebug and it appears I am doing something wrong as the you will see in the screenshots.

I do have code that rebind the listbox. The data is stored in a text field like so "12345|23456|34567|67890" so I have a process which splits these into an array and then loop through the array to bind to the listbox. Shown below:

            Try 
                Dim strSupervisors As String = employee.SupervisorNumber 
                Dim arrSupervisors As Array = Split(strSupervisors, "|"
                PopulateItems(radList, arrSupervisors) 
            Catch ex As Exception 
                DebugInfo("radList: " & ex.Message) 
            End Try 

    Private Shared Sub PopulateItems(ByVal listBox As RadListBox, ByVal array As Array) 
        For x As Integer = 0 To UBound(array) - 1 
            If Len(array(x)) > 5 Then 
                Dim item As New RadListBoxItem(GetUsernameFromEmployeeNumber(array(x)), array(x)) 
                listBox.Items.Add(item) 
            End If 
        Next 
    End Sub 

    Private Shared Function GetUsernameFromEmployeeNumber(ByVal strEmployeeNumber As StringAs String 
        Dim strReturn As String = "" 
        Try 
            Dim db = New Modules.EmployeeManagement.EmployeeManagementDataContext 
            Dim employee = (From t In db.tblAuthors Where t.EmployeeNumber = strEmployeeNumber Select t).Single 
            strReturn = employee.Username 
        Catch ex As Exception 
            strReturn = ex.Message 
        End Try 
        Return strReturn 
    End Function 

0
Genady Sergeev
Telerik team
answered on 25 May 2010, 08:03 AM
Hi Joshua,

The screenshots looks correct. This is the way the client state should look before and after hitting save. I.e. it should have values in the log entry before save and empty log after that. It seems that the problem comes from the way the listboxes are rebound. There is no need to add the items manually after they were first added. RadListBox will "remember" that there are items transferred. I suggest that you revise your server-side code and more specifically the PopulateItems method. You shouldn't invoke it on Save click. Where do you call that method and when?

Kind regards,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Genady Sergeev
Telerik team
answered on 25 May 2010, 08:04 AM
Hi Joshua,

The screenshots looks correct. This is the way the client state should look before and after hitting save. I.e. it should have values in the log entry before save and empty log after that. It seems that the problem comes from the way the listboxes are rebound. There is no need to add the items manually after they were first added. RadListBox will "remember" that there are items transferred. I suggest that you revise your server-side code and more specifically the PopulateItems method. You shouldn't invoke it on Save click. Where and when do you call that method?

Kind regards,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ListBox
Asked by
Joshua
Top achievements
Rank 2
Answers by
Genady Sergeev
Telerik team
Joshua
Top achievements
Rank 2
Share this question
or