Share This
 
All Posts  /  Kentico Development Tips  /  March 25, 2016 

Kentico Quick Tip: Access the list of options entered into a page type control setting

It is common for Kentico administrators to limit the field options that editors can select from when creating a new page from a custom page type. In many cases developers need to create filters to allow users to filter by that list of options. In this post I will show you how to access the page type form field information and add it to a drop down list for filtering.
 

Kentico makes custom development a breeze. You can easily access form field settings using the DataClassInfoProvider as shown below.


    protected string[] GetFormFieldOptions()
    {
        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
        if (dci != null)
        {
            //Get the data from the form field
            FormInfo fi = new FormInfo(dci.ClassFormDefinition);
            FormFieldInfo ffi = fi.GetFormField("Industry");
            string[] industries = ffi.Settings["Options"].ToString().Split('\n'); 
            return industries;
        }
        return null;
    }

Then you simply loop through the array and add the items to a drop down list.


        string[] industries = GetFormFieldOptions();
            if(industries != null){
                ddlIndustry.Visible = true;
                //Add blank field to drop down list
                ListItem li_blank = new ListItem();
                li_blank.Text = "--Select Industry--";
                li_blank.Value = "";
                ddlIndustry.Items.Add(li_blank);
                
                //Add the industries to the drop down list
                foreach (string industry in industries)
                {
                    ListItem li = new ListItem();
                    li.Text = industry.Trim();
                    li.Value = industry.Trim();
                    ddlIndustry.Items.Add(li);
                }
            }        

Take a look at Kentico's documentation to learn more about creating custom filters.

Note: If you want to get the options from an alternative form you would use AlternativeFormInfoProvider. 

AlternativeFormInfo afp = AlternativeFormInfoProvider.GetAlternativeFormInfo("customtable.MyTableName.MyAlternativeForm");  
FormInfo fi = new FormInfo(afp.FormDefinition);

 

Show More
Share This
 
Comments
Blog post currently doesn't have any comments.
*
 Security code
*
ADD COMMENT
Social Buzz

Get in Touch

Contact

Contact
t: 973.539.5255
f: 973.917.4730

Visit

Visit
715 Main Street
Boonton, NJ 07005

Locations

Locations
Boonton
Dallas
Jersey City
Boulder

Send Us a Message




 Security code