引言
上篇未完的精彩继续,另一条信息的获取是登陆权限对应的人名。在项目中,需要在一个下拉框中包含进去他们的名字。与上篇同样用对比的方式进行展示。
按钮效果
写死的页面代码
<span style="font-size:18px;"><select id="watch" class="easyui-combobox" name="watch" data-options="required:true">
<asp:Label ID="Options" runat="server" Text="Label"></asp:Label>
<option>潘阿召</option>
<option>张蒙</option>
</select></span>
用到配置文件改动后
<span style="font-size:18px;"><select id="watch" class="easyui-combobox" name="watch" data-options="required:true">
<asp:Label ID="Options" runat="server" Text="Label"></asp:Label>
<%--<option>潘阿召</option>
<option>张蒙</option>--%>
</select></span>
后台代码
string elements = ConfigurationManager.AppSettings["DropdownlistElements"];
var values = elements.Split(';');
var optionsStr = new StringBuilder();
foreach (var val in values)
{
if (string.IsNullOrEmpty(val)) continue;
optionsStr.AppendFormat("<option>{0}</option>", val);
}
this.Options.Text = optionsStr.ToString();
小结
这样就不用再改动代码,只改动配置文件就可以,做到了灵活可配。