Populating Dropdown lists with no database representation when loading an UIForm

Andrei Panait asked on March 27, 2017 18:30

I have a custom class containing 4 fields without database representation. Those fields are used to select and filter the values for the actual fields which are getting stored in the database. The filtering is done by SQL query based on dependency fields. All goes well when adding new items, the dependent fields are getting updated accordingly. For editing an item I need to reload the data in the dropdown lists in order to select the values. Setting the correct values (IDs) is done under Control_OnAfterDataLoad like this:

form.FieldEditingControls["Gender"].SetValue(item.Gender); form.FieldEditingControls["ItemsList"].SetValue(item.ItemListID);

The ItemsList dropdown is populated based on the selected Gender. When editing the item, the ItemsList is not populated with the correct items, si selecting the values item.ItemListID does not work.

How can I the dropdown list with no database representation being populated with the correct list of items (as per the sql query in the field definition) when editing the item?

Recent Answers

Suneel Jhangiani answered on March 28, 2017 13:22

How have you defined the DropDownLists? Are you sure that the dropdowns have both Value and Text parameters as I believe SetValue would be looking for the Value as opposed to the Text within the Dropdown.

0 votesVote for this answer Mark as a Correct answer

Andrei Panait answered on March 28, 2017 15:49

Yes, I have both Value and Text.

The problem is with populating the DropDownList fields of the UIForm when editing an already existing item. These dropdowns are dependent on each other. For example the second dropdown in the form depends on the value selected in the first dropdown. Also the Info Class do not contain properties for the fields without database representation.

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on March 31, 2017 20:31

I'm not too familiar with how UIForms work with dependent fields, but I guess that when you change a dropdown value it triggers a postback to filter the data. Therefore, I would guess that in the method where you are trying to set the control value you should be setting the first dropdown's selected value, then rebuilding the second dropdown's data and setting its value, and so on for the other 2 dropdowns. The key is reloading the data for a subsequent dropdown when you set a value in previous dropdown.

Should look like:


DropDownItemsList_LoadData(); // you would need to implement this as a method or inline code


0 votesVote for this answer Mark as a Correct answer

Andrei Panait answered on April 3, 2017 09:54

Thank you Suneel.

How do I get access to the DropDownList control in order to trigger a reload, if I know the field name, like in my example?

0 votesVote for this answer Mark as a Correct answer

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