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

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?

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

Related

Load SettingDefinitionProvider with additional properties from database

I am using separate DB per Tenant. I ran into a scenario where I need to load the settings definitions from the DB. The reason for it is each Tenant can have its own default values. So I want to copy the default values over to the new tenants created by cloning the parent tenant DB and override the default values. However, I also want to update the other fields or add new columns ex: IsVisibleToClients can change per tenant and I cannot have this value in application code but instead want it in the DB
Is this currently supported or a way to handle this
Able to override the settings but looking to save all default values to DB. I believe this can be done by creating seeding scripts.
And new tenants can be creating by cloning this DB and then override the default values. But how can I manage the fields like IsVisibleToClients per tenant and add other custom columns
Creating Custom Setting Value Providers is explained in Abp's own documentation, you can use it.(https://docs.abp.io/en/abp/latest/Settings#custom-setting-value-providers)
public class CustomSettingValueProvider : SettingValueProvider
{
public override string Name => "Custom";
public CustomSettingValueProvider(ISettingStore settingStore)
: base(settingStore)
{
}
public override Task<string> GetOrNullAsync(SettingDefinition setting)
{
/* Return the setting value or null
Use the SettingStore or another data source */
}
}
Configure<AbpSettingOptions>(options =>
{
options.ValueProviders.Add<CustomSettingValueProvider>();
});

View Switcher for ServiceStack?

In MVC, there's a ViewSwitcher, and you can add _Layout, _Layout.mobile; MyView and optional MyView.mobile
What's the best way to accomplish this in ServiceStack razor view? Thanks
ServiceStack doesn't implicitly switch layouts at runtime, instead the preferred layout needs to be explicitly set. ServiceStack's RazorRockstars Demo website explains how to dynamically switch views, i.e:
Change Views and Layout templates at runtime
The above convention is overrideable where you can change both what View and Layout Template is used at runtime by returning your Response inside a decorated HttpResult:
return new HttpResult(dto) {
View = {viewName},
Template = {layoutName},
};
This is useful whenever you want to display the same page in specialized Mobile and Print Preview website templates. You can also let the client change what View and Template gets used by attributing your service with the ClientCanSwapTemplates Request Filter Attribute:
[ClientCanSwapTemplates]
public class RockstarsService : RestServiceBase { ... }
Which itself is a very simple implementation that also shows you can you can swap the View or Template used inside a Request Filter:
public class ClientCanSwapTemplatesAttribute : RequestFilterAttribute
{
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
req.Items["View"] = req.GetParam("View");
req.Items["Template"] = req.GetParam("Template");
}
}
This attribute allows the client to change what View gets used with the View and Template QueryString or FormData Request Params. A live example of this feature is used to change the /rockstars page:
/rockstars?View=AngularJS
/rockstars?Template=SimpleLayout
/rockstars?View=AngularJS&Template=SimpleLayout
Changing Layout used from inside a view
You can even change the layout used by setting the Layout property from inside a Razor View, e.g:
#inherits ViewPage<Response>
#{
Layout = IsMobileRequest(base.Request) ? "_LayoutMobile" : "_Layout";
}

Update objectchoice field list on Blackberry

I'm new to Blackberry and I'm currently working on it. I have an ObjectChoiceField that uses a string array as its dataset. How can i update the display of the ObjectChoiceField list based on the change of array elements?
I want to do similar thing like notifyDataSetChanged() on Android development.
Update your ObjectChoiceField instance (let say myObjectChoiceField), via setChoices(String[] newChoices) method. Assume newChoicesStringArray is a String array with new option values.
Application.getApplication().invokeLater(new Runnable() {
public void run() {
myObjectChoiceField.setChoices(newChoicesStringArray);
}
});
invokeLater() is used to avoid UI event locking upong field update action.

ASP.NET MVC dropdownlist with entity framework

I'm new to asp.net mvc and the entity framework and i'm trying to make a dropdownlist with data out of my database. I have the following:
Controler:
//
// GET: /StoreEditor/Edit/(ID)
public ActionResult Edit(int id)
{
StoreEditorViewModel data = new StoreEditorViewModel(id);
return View(data);
}
ViewModel:
public StoreEditorViewModel(int id)
{
using (MvcTicketsEntities storeDB = new MvcTicketsEntities())
{
details = (from t in storeDB.Tickets.Include("Artists").Include("Genres")
where t.TicketId == id
select t).FirstOrDefault();
}
}
Now i get get all my labels and editors in de view. But how do i make a dropdownlist with all the names in the database table GENRES in the field NAME.
The table GENRES has 2 fields GenreId and Name.
Please refer to the below link:
http://codeclimber.net.nz/archive/2009/08/10/how-to-create-a-dropdownlist-with-asp.net-mvc.aspx
This explains quite well, how to approach it.
Basically, you would need to create List<SelectListItem> object and supply it to the dropdown list.
Thanks

Can we bind dynamic data (dataset or list) to a control in WPF

I have a user control...and the base page(s) which uses this user control has a dataset which will be used by the user control.
My dataset is dynamic...means..it can have different number of columns depending upon which page my usercontrol is implemented. Is there any control in wpf which i can use to bind this dataset (without knowing the column information) ...i mean similar to datagrid/gridview in 2.0 ?
Take a look at the WPF toolkit, this contains a Grid which meets your requirements.
This toolkit is built by Microsoft, and part of the Microsoft Shared Source Initiative (see the link I provided).
It's not supported my Microsoft though, so if you get a bug you can use their forums but not call MS support.
If you do want to do it yourself, you can for example write some code that takes a List<T>, you get the generic type, get the properties, iterate over them, write the column headers, iterate over all the items in the list and write all the properties.
I wrote this code a while back to write a List to an HTML table, I hope it's useful:
public void PrintList<T>(List<T> list)
{
if(null!=list.FirstOrDefault())
{
Type t = typeof(list[0]);
PropertyInfo[] properties = t.GetProperties();
// properties = list of all properties.
print("<table><tr>");
foreach(var property in properties)
{
// print property title
print(string.Format("<th>{0}</th>", property.Name));
}
print("</tr>");
foreach(var item in list)
{
print("<tr>");
foreach(var property in properties)
{
var propertyValue = t.InvokeMember(property.Name, BindingFlags.GetProperty, null, item, new object[] {});
print(string.Format("<td>{0}</td>", propertyValue));
}
print("</tr>");
}
print("</table>");
}
}

Resources