|
Front-end Page 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 = ""> "〉
<Asp: textbox id = "textbox1" style = "Z-INDEX: 101; left: 164px; position: absolute; top: export PX "runat =" server "width =" 204px "Height =" 25px "> </ASP: textbox> 〉
<Asp: button id = "button1" style = "Z-INDEX: 102; left: pixel; 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> 〉
Backend CS 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 (for example, 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 method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary> 〉
Private void initializecomponent ()
{
This. button1.click + = new system. eventhandler (this. button#click );;
This. Load + = new system. eventhandler (this. page_load );;
}
# Endregion
Private void button#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 );;
} |