色尼玛亚洲综合影院,亚洲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 用戶控件讀取以及賦值,轉載需保留來源!

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

主站蜘蛛池模板: 濉溪县| 杂多县| 沙湾县| 乡城县| 涞源县| 加查县| 买车| 河西区| 蛟河市| 四平市| 大洼县| 隆德县| 甘谷县| 泸西县| 南丹县| 呼伦贝尔市| 宣汉县| 富锦市| 和平县| 柳江县| 仁布县| 乐陵市| 合肥市| 弥渡县| 固原市| 玛沁县| 英超| 海淀区| 波密县| 镇康县| 南雄市| 商水县| 巴彦淖尔市| 财经| 饶河县| 临潭县| 县级市| 永和县| 无为县| 定襄县| 朝阳区|