Custom form control with multi-select items from custom table

A M asked on April 19, 2018 23:09

Hello,

I am trying to create a custom form control that will provide the ability to multi-select items from a custom table. I am following the steps listed in this article.

In the "ascx" file I replaced the UniSelector ObjectType from cms.user to customtableitem.namespace.MyCustomTable.

In the "ascx.cs" file I changed the GetDataSource() method return type from InfoDataSet<UserInfo> to InfoDataSet<CMS.CustomTables.Types.namespace.MyCustomTableItem>. When I select a custom table item, I am getting the following error:

Unable to cast object of type 'CMS.DataEngine.InfoDataSet1[CMS.CustomTables.CustomTableItem]' to type 'CMS.DataEngine.InfoDataSet1[CMS.CustomTables.Types.namespace.MyCustomTableItem]'.

Then I tried changing the return type to InfoDataSet<CMS.CustomTables.CustomTableItem>. Now when I select a custom table item, I am getting a different error:

Object type '[Unknown]' not found.

The error is located in the foreach statement from the MultipleSelector_OnSelectionChanged() method.

Can you please point me into the right direction? I couldn't find a working example for custom tables.

Thank you in advance.

Recent Answers


Prashant Verma answered on April 21, 2018 03:00 (last edited on April 23, 2018 08:40)

Hi AM,

You can use this multi selector custom form control which I created for one of my requirement.It's exactly similar what you are looking for please go through it and let me know if any issue you were facing in import this. https://devnet.kentico.com/marketplace/inline-controls/bootstrap-multi-selector

Thanks

Happy to help!

0 votesVote for this answer Mark as a Correct answer

A M answered on April 23, 2018 16:07 (last edited on April 23, 2018 16:08)

Hi,

Thank you for your quick reply. I downloaded the code but I am getting some errors regarding the "FormHelper" class.

FormHelper does not contain a definition for:

GetSelectedValuesFromListItemCollection()

LoadItemsIntoList()

SelectMultipleValues()

I had to add "using CMS.FormEngine.Web.UI;" at the top for "FormEngineUserControl"

I also had to comment out "using CMS.FormControls;" because "FormControls does not exist in the namespace CMS" error.

Am I doing something wrong?

P.S.: I am using Kentico 10.

Thank you very much.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.