Get choice field from dynamic module

Here is a simple way to get the list of possible values of a choice field of a dynamic module from code behind

Code snippet is given below.

var manager = ModuleBuilderManager.GetManager();
//Bind Choice field
var fieldList = manager.Provider.GetDynamicModuleFields().Where(f => f.Name == "YOUR_FIELD_NAME" && f.FieldNamespace == "YOUR_DYNAMICMODULE_NAMESPACE").Single();
var options =fieldList.Choices.Trim().Split(',');
TextReader txtReader = new StringReader(options[0]);
DataSet ds = new DataSet();
XmlReader reader = new XmlTextReader(txtReader);
//You will get list of choice field in xml
//And will convert it into DataTable
if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
    drpSelect.DataSource = ds.Tables[0];
    drpSelect.DataTextField = "text";
    drpSelect.DataValueField = "value";

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: