I needed to list all AppSetting keys in a configuration page from the Web.Config.
问问题
515 次
1 回答
0
Here is the VB.Net Code behind.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim appSettings As NameValueCollection = ConfigurationManager.AppSettings
Dim DT As New DataTable
Dim DR As DataRow
Dim AppKey = New DataColumn("AppKey", Type.GetType("System.String"))
Dim AppValue = New DataColumn("AppValue", Type.GetType("System.String"))
DT.Columns.Add(AppKey)
DT.Columns.Add(AppValue)
For Each Key In appSettings.AllKeys
DR = DT.NewRow()
DR("AppKey") = Key
DR("AppValue") = appSettings.Item(Key)
DT.Rows.Add(DR)
Next
Dim DS As New DataSet()
DS.Tables.Add(DT)
AppSettingKeys.DataSource = DS
AppSettingKeys.DataBind()
End If
End Sub
Here is the Page:
<table>
<asp:Repeater ID="AppSettingKeys" runat="server">
<ItemTemplate>
<tr><td class="table-left-class2"><%#Eval("AppKey")%></td><td><%#Eval("AppValue")%></td></tr>
</ItemTemplate>
</asp:Repeater>
</table>
于 2014-10-17T08:40:00.550 回答