色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

asp.net 用戶控件讀取以及賦值

XML內容如下:
復制代碼 代碼如下:
<?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";

//// <summary>
/// 下拉框賦值
/// </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" //目前只顯示CN
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)
{
ddlVersion.SelectedValue=Value;
}
}
}

AspNet技術asp.net 用戶控件讀取以及賦值,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 焉耆| 崇义县| 吐鲁番市| 九龙城区| 苏州市| 嘉义市| 河东区| 沐川县| 汉中市| 景谷| 砚山县| 黄石市| 江永县| 安丘市| 德州市| 西乌珠穆沁旗| 正安县| 玉屏| 镇江市| 土默特右旗| 宁德市| 临猗县| 金寨县| 鲁山县| 铜川市| 增城市| 太谷县| 新安县| 金平| 布尔津县| 玉龙| 新郑市| 庆元县| 许昌县| 沛县| 沧州市| 南投市| 宁国市| 建瓯市| 沙坪坝区| 岐山县|