Binding XML and K2ListBox

  • 4 April 2007
  • 3 replies
  • 2 views

Badge +2
Hello,
I'm desperatly trying to bind a k2 listbox with an XML Field (K2 Property).
I tried anything but the right solution, and don't succeed, when I try to view data (K2 Workspace), I just have the XML Structure, but empty.
please help me !
does anyone have a sample, a process I could follow, or anything else ?
many thanks
Thibaut

3 replies

Badge +8
A common misconception is that you can bind an XML datafield to a K2 dropdown list and visa versa and that all the values (options) are passed back and fro. This is not the case however and it is by design. It s also the way standard ASP.NET controls work. Let me explain:

A normal ASP.NET dropdown list have 2 main properties used:
1. DataSource List of items
2. SelectedItem Current item selected
So when creating a page, you typically set the DataSource property in the page load by making a call to a lookup table.
Then when the user submits the page, you typically get the selected item s value and/or text.

So to translate this back to a SmartForm, the behaviour is exactly the same. When the page is loaded, you will need to get the DataSource for the K2 Dropdown list. This has to be done again from an external source, or hard coding the items. When the user clicks the K2 Button to Update or Finish the item, only the selected value will be populated to the K2 DataField assigned to the list. The unselected entries will not be saved.

Hope this helps and that I didn t misunderstand your problem.
Badge +2
Many thanks for those precisions !
is there a (simple) solution to save the content of a k2listbox to a xmlfield ?
My K2ListBox is filled by code and I need to save the values.
Thibaut
Badge +8
A possible solution is to populate a hidden K2DataGrid with the same values that you populate the Listbox with. Then bind the K2 DataGrid to a K2 XML Datafield.

Reply