The XML content is as follows:
CopyCode The Code is as follows: <? XML version = "1.0" encoding = "UTF-8"?>
<Systemversion>
<Item>
<Version_id> 1 </version_id>
<Version_name> CN </version_name>
</Item>
<Item>
<Version_id> 2 </version_id>
<Version_name> en </version_name>
</Item>
</Systemversion>
Key code of the user control:
Systemversion. ascxCopy codeThe Code is as follows: <% @ Control Language = "C #" autoeventwireup = "true" codefile = "systemversion. ascx. cs" inherits = "usercontrols_systemversion" %>
<! -- Value is the input value -->
<Div style = "white-space: nowrap">
<Asp: dropdownlist id = "ddlversion" runat = "server">
</ASP: dropdownlist>
</Div>
Background File:Copy codeThe Code is as follows: using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Data;
Using system. xml;
Using system. xml. LINQ;
Public partial class usercontrols_systemversion: system. Web. UI. usercontrol
{
Private const string con_filepath = "~ /App_data/sysversion. xml ";
//// <Summary>
/// Drop-down box assignment
/// </Summary>
Public String Value
{
Set {viewstate ["value"] = value ;}
Get {return viewstate ["value"] = NULL? Null: viewstate ["value"]. tostring (). Trim ();}
}
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Ddlbind ();
}
}
Public void ddlbind ()
{
Xelement xdoc = xelement. Load (server. mappath (con_filepath ));
// Create the query
VaR lversion = from C in xdoc. descendants ("item ")
Where C. element ("version_id"). value = "1" // currently, only CN is displayed.
Select New
{
Version_name = C. element ("version_name"). value,
Version_id = C. element ("version_id"). Value
};
ddlversion. datasource = lversion. tolist ();
ddlversion. datatextfield = "version_name";
ddlversion. datavaluefield = "version_name";
ddlversion. databind ();
If (value! = NULL)
{< br> ddlversion. selectedvalue = value;
}< BR >}