Front Code
<%@ Page language= "C #" codebehind= "WebForm1.aspx.cs" autoeventwireup= "false" inherits= "Webapplication1.webform1" %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft Visual Studio 7.0" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript (ECMAScript)" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
<body ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<font face= "Song Body" >
<asp:textbox id= "TextBox1" style= "Z-INDEX:101; left:164px; Position:absolute; top:190px "runat=" Server "width=" 204px "height=" 25px "></asp:TextBox>
<asp:button id= "Button1" style= "z-index:102; left:386px; Position:absolute; top:188px "runat=" Server "width=" 78px "height=" 25px "text=" button "></asp:Button>
<asp:dropdownlist id= "DropDownList1" style= "z-index:103; left:29px; Position:absolute; top:192px "runat=" Server "width=" 130px "height=" 22px "></asp:DropDownList>
</FONT>
</form>
</body>
</HTML>
CS page Code
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using System.Xml;
Namespace WebApplication1
{
<summary>
Summary description for WebForm1.
</summary>
public class WebForm1:System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Button Button1;
Public WebForm1 ()
{
Page.Init + = new System.EventHandler (Page_Init);
}
private void Page_Load (object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
Open a file (assuming the web. Config in the root directory)
String Filename=server.mappath ("/") + @ "/web.config";
XmlDocument xmldoc= New XmlDocument ();
XmlDoc. Load (filename);
XmlNodeList Topm=xmldoc. Documentelement.childnodes;
foreach (xmlelement element in topm)
{
if (element. Name.tolower () = = "appsettings")
{
XmlNodeList _node=element. ChildNodes;
if (_node. Count >0)
{
DropDownList1.Items.Clear ();
foreach (XmlElement el in _node)
{
DropDownList1.Items.Add (el. attributes["Key"]. INNERXML);
}
}
}
}
}
}
private void Page_Init (object sender, EventArgs e)
{
InitializeComponent ();
}
#region Web Form Designer generated code
<summary>
Required to Designer support-do not modify
The contents is with the Code Editor.
</summary>
private void InitializeComponent ()
{
This. Button1.Click + = new System.EventHandler (this. Button1_Click);
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
private void Button1_Click (object sender, System.EventArgs e)
{
String Filename=server.mappath ("/") + @ "/web.config";
XmlDocument xmldoc= New XmlDocument ();
XmlDoc. Load (filename);
XmlNodeList Topm=xmldoc. Documentelement.childnodes;
foreach (xmlelement element in topm)
{
if (element). Name.tolower () = = "appsettings")
{
XmlNodeList _node=element. ChildNodes;
if (_node. Count >0)
{
foreach (XmlElement el in _node)
{
if (el. attributes["Key"]. Innerxml.tolower () ==this. DropDownList1.SelectedItem.Value.ToLower ())
{
El. attributes["Value"]. Value=this. TextBox1.Text;
}
}
}
}
}
xmldoc. Save (filename);
}
}
}