Andy Green
Top achievements
Rank 2
Andy Green
asked on 07 Aug 2012, 02:00 PM
I have a list in a RadDropDown, that users can select multiple values from, these are then saved to a database in a comma separated string.
When I wish to edit the data I need the same checkboxes to be ticked.
My code is atttached, I'm getting the first value to tick, but on subseqent values the x is null and no further binding takes place. The value of the selectedItem matched the value of Usr from the array.
Andy
When I wish to edit the data I need the same checkboxes to be ticked.
My code is atttached, I'm getting the first value to tick, but on subseqent values the x is null and no further binding takes place. The value of the selectedItem matched the value of Usr from the array.
'populate the dropdown and pre select checkboxesIf Not IsDBNull(u_ds.Tables(0).Rows(0)("LinkedUsers")) Then Dim arrLinkedUsers As Array = Split(u_ds.Tables(0).Rows(0)("LinkedUsers"), ",") For Each Usr In arrLinkedUsers ddlClinic.SelectedValue = Usr Dim x As RadComboBoxItem = DirectCast(ddlClinic.SelectedItem, RadComboBoxItem) If Not x Is Nothing Then x.Checked = True End If Next UsrEnd IfAndy
5 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Aug 2012, 04:56 AM
Hi,
Try the following code to achieve your scenario.
VB:
Hope this helps.
Thanks,
Princy.
Try the following code to achieve your scenario.
VB:
Dim data As String = dt.Rows(0)("LinkedUsers").ToString()If data.Length > 0 Then Dim arrLinkedUsers As String() arrLinkedUsers = data.Split(","C) For Each Usr As String In arrLinkedUsers If RadComboBox1.Items.FindItemByValue(Usr) IsNot Nothing Then RadComboBox1.Items.FindItemByValue(Usr).Checked = True End If NextEnd IfHope this helps.
Thanks,
Princy.
0
Andy Green
Top achievements
Rank 2
answered on 08 Aug 2012, 06:54 AM
Thanks Princy, but this is the same. There are for example 3 items in the array, these values are also in the dropdown as values, but it will only ever tick the first one it comes to.
This is my markup:
This is the line that only returns true for the first item in the array -
Andy
This is my markup:
<telerik:RadComboBox ID="ddlClinician" Runat="server" Width="245px" EnableEmbeddedSkins="false" Skin="Activity" CheckBoxes="true" emptyMessage=" "></telerik:RadComboBox>
If data.Length > 0 Then Dim arrLinkedUsers As String() arrLinkedUsers = data.Split(","c) For Each Usr As String In arrLinkedUsers If ddlClinician.Items.FindItemByValue(Usr) IsNot Nothing Then ddlClinician.Items.FindItemByValue(Usr).Checked = True End If NextEnd IfThis is the line that only returns true for the first item in the array -
If ddlClinician.Items.FindItemByValue(Usr) IsNot Nothing Then
Andy
0
Princy
Top achievements
Rank 2
answered on 09 Aug 2012, 06:21 AM
Hi,
Please modify the code as follows to check every radcombobox items having the values in the array.
VB:
Thanks,
Princy.
Please modify the code as follows to check every radcombobox items having the values in the array.
VB:
If data.Length > 0 Then Dim arrLinkedUsers As String() arrLinkedUsers = data.Split(","C) For Each Usr As String In arrLinkedUsers Dim selected As IEnumerable(Of RadComboBoxItem) = ddlClinician.Items.Where(Function(item) item.Value = Usr) For Each item As RadComboBoxItem In selected item.Checked = True Next NextEnd IfThanks,
Princy.
0
Andy Green
Top achievements
Rank 2
answered on 10 Aug 2012, 07:11 AM
Still the same,it only finds the first in the list.
Where should this code be run, My current set up populates the drop down list with data on a page load, and I have a function that gets the user record, and currently its here that I'm trying to re populate the checkbox ticks.
Andy
Where should this code be run, My current set up populates the drop down list with data on a page load, and I have a function that gets the user record, and currently its here that I'm trying to re populate the checkbox ticks.
Andy
0
Andy Green
Top achievements
Rank 2
answered on 10 Aug 2012, 07:22 AM
Hi Princy
This is now working and it looks like it was my fault, and sorry for wasting your time.
On closer inspection of the data, there was a leading space, which of course wouldn't match up witht he list data.
Andy
This is now working and it looks like it was my fault, and sorry for wasting your time.
On closer inspection of the data, there was a leading space, which of course wouldn't match up witht he list data.
Andy