Posted 03 May 2010
Link to this post
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.
|<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 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" > |
I have this wired up to a Save button in my Sitefinity Module.
|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.EmployeeName= txtName.Text |
|employee.UserGroup = radUserGroup.SelectedValue |
|For Each item As RadListBoxItem In radList.Items |
| sb.Append(item.Value.ToString & "|") |
|employee.SupervisorNumber = Left(sb.ToString, 59) |
|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.