I'm attempting to have the new RadComboBox with checkboxes="true" bound to a SqlDataSource inside a radGrid.
It works fine when just 1 item is selected, but when I select multiple Items it doesn't work. I try to convert all the selected countries ids into a comma separated string and then add an updateparameter to update the database. But it doesn't update it. I'm not sure what I'm doing wrong.
I'll also like to know the proper way to populate the checkboxes in the radcombobox automatically, when editmode is enabled on the grid.
It works fine when just 1 item is selected, but when I select multiple Items it doesn't work. I try to convert all the selected countries ids into a comma separated string and then add an updateparameter to update the database. But it doesn't update it. I'm not sure what I'm doing wrong.
I'll also like to know the proper way to populate the checkboxes in the radcombobox automatically, when editmode is enabled on the grid.
<
telerik:GridTemplateColumn
HeaderText
=
"Select Countries"
ItemStyle-Width
=
"240px"
UniqueName
=
"List_of_Countries"
>
<
ItemTemplate
>
<%# DataBinder.Eval(Container.DataItem, "List_of_Countries")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"rdComboCountries"
DataTextField
=
"country_name"
CheckBoxes
=
"true"
Width
=
"250px"
DataValueField
=
"country_id"
DataSourceID
=
"SqlDataSourceCountries"
SelectedValue='<%#Bind("List_of_Countries") %>'>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
asp:SqlDataSource
runat
=
"server"
ID
=
"SqlDataSourceCountries"
ConnectionString="<%$ ConnectionStrings:mydbConnectionString %>"
ProviderName="<%$ ConnectionStrings:mydbConnectionString.ProviderName %>"
SelectCommand="SELECT country_id, Country_names FROM lu_countries">
</
asp:SqlDataSource
>
Private
Sub
rgCountries_UpdateCommand(sender
As
Object
, e
As
Telerik.Web.UI.GridCommandEventArgs)
Handles
rgCountries.UpdateCommand
Dim
editItem
As
GridDataItem = e.Item
'Pass the parameter values to the SqldataSource
oDSMySqlCountries.UpdateParameters.Add(
New
Parameter(
"list_of_countries"
))
oDSMySqlCountries.UpdateParameters(
"list_of_countries"
).DefaultValue = GetCheckedItems(
DirectCast
(editItem.FindControl(
"rdComboCountries"
), RadComboBox))
'Update the values
oDSMySqlCountries.Update()
'Bind the RadGrid again
rgCountries.Rebind()
End
Sub
Private
Function
GetCheckedItems(
ByVal
comboBox
As
RadComboBox)
As
String
Dim
sb
As
New
StringBuilder()
Dim
collection
As
IList(Of RadComboBoxItem) = comboBox.CheckedItems
For
Each
item
As
RadComboBoxItem
In
collection
sb.Append(item.Value +
", "
)
Next
Return
sb.ToString.TrimEnd(
" "
).TrimEnd(
","
)
End
Function