DNN 主题。如何从设置中填充 DropDownList 值?

DNN Theme. How to populate DropDownList values from a setting?

我一直在为几个客户开发 DNN 主题。 主题有一个 DropDownList,它的值对于每个客户端都是不同的。我不想创建很多主题(每个客户端一个),因为 DropDownList 值是它们之间唯一的区别。

如何根据一些主题配置填写DropDownList值?

为了在我的主题上实现这种行为,我使用 DotNetNuke.Common.Utilities.Config class.

  • 首先,我在 dnn web.config 中创建了一个应用程序设置。

您可以手动执行此操作: <add key="DropDownListValues" value="Value1,Value2,Value3" />

...或者您可以从代码中添加这些值:

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);

    }
  • 有了这个 属性 你总是可以这样填充你的 DropDownList:

        var stylesCommaSeparated = DotNetNuke.Common.Utilities.Config.GetSetting("DropDownListValues");
        stylesCommaSeparated.Split(',').ForEach(setting=>DropDownList1.Items.Add(setting));