最近项目中看到同事写的一个用户控件,是一个下拉,值是从XML中读取的,而且这部分还用到了LINQ读取XML的知识,最近才看了一点点LINQ的知识,当记录一下吧。XML内容如下:
XML/HTML
- <?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>
用户控件的关键代码:
SystemVersion.ascx
- <%@ Control Language="C#" AutoEventWireup="true" CodeFile="SystemVersion.ascx.cs" Inherits="UserControls_SystemVersion" %>
- <!-- Value是传入的值 -->
- <div style="white-space:nowrap">
- <asp:DropDownList ID="ddlVersion" runat="server">
- </asp:DropDownList>
- </div>
后台文件:
- 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";
-
-
-
-
- public string Value
- {
- set { ViewState["Value"] = value; }
- get { return ViewState["Value"] == null ? null : ViewState["Value"].ToString().Trim(); }
- }
-
|