0

I have been working on a DNN theme for several clients. The theme has a DropDownList and its values ​​are different for each client. I do not want to create many themes (one per client) because the DropDownList values ​​are the only difference between them.

How can I fill in the DropDownList values ​​based on some theme configuration?

Erick Lanford Xenes
  • 1,467
  • 2
  • 20
  • 34

1 Answers1

0

In order to implement this behivor on my theme I use DotNetNuke.Common.Utilities.Config class.

  • First I create an App Setting in the dnn web.config.

You can do this manually: <add key="DropDownListValues" value="Value1,Value2,Value3" />

...or you can add these values from code:

public static void AddAppSetting(string name, string value)
    {
        var xmlDocument = DotNetNuke.Common.Utilities.Config.AddAppSetting(DotNetNuke.Common.Utilities.Config.Load(), name, value);
        DotNetNuke.Common.Utilities.Config.Save(xmlDocument);

    }
  • Having this property you can always populate your DropDownList this way:

        var stylesCommaSeparated = DotNetNuke.Common.Utilities.Config.GetSetting("DropDownListValues");
        stylesCommaSeparated.Split(',').ForEach(setting=>DropDownList1.Items.Add(setting));
    
Erick Lanford Xenes
  • 1,467
  • 2
  • 20
  • 34
  • 1
    Very interesting approach - but be advised that using the `AddAppSetting` function - each save would trigger an application pool recycle. Which could be an issue depending on how you use it and who's adding settings. – ajwaka Jun 20 '18 at 11:27