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

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

主站蜘蛛池模板: 衡阳市| 如东县| 安乡县| 香格里拉县| 陇西县| 太谷县| 永安市| 大厂| 城固县| 五峰| 海兴县| 荥经县| 甘泉县| 蓝山县| 四川省| 涡阳县| 曲阜市| 康保县| 岳普湖县| 肃宁县| 桂林市| 余江县| 香河县| 油尖旺区| 务川| 壤塘县| 得荣县| 黄梅县| 宝山区| 陵川县| 塔城市| 三穗县| 石渠县| 大同市| 龙岩市| 扬州市| 平定县| 万荣县| 永兴县| 汤原县| 都匀市|