我需要从Web.Config列出配置页面中的所有AppSetting键。
答案 0 :(得分:0)
这是后面的VB.Net代码。
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
这是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>