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

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

主站蜘蛛池模板: 成武县| 榆树市| 巴楚县| 宽甸| 望江县| 秭归县| 巧家县| 井研县| 高雄市| 武平县| 义马市| 那曲县| 华池县| 泰安市| 绥芬河市| 山丹县| 陕西省| 凉山| 龙陵县| 法库县| 吉首市| 嘉峪关市| 石楼县| 邹城市| 贵定县| 浑源县| 临城县| 常山县| 乐清市| 聊城市| 岳阳县| 信宜市| 洛阳市| 保德县| 尖扎县| 灵山县| 宝坻区| 金华市| 库尔勒市| 木兰县| 桐梓县|