国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:19:36
字體:
供稿:網(wǎng)友
XML內(nèi)容如下:

復(fù)制代碼 代碼如下:


<?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>


用戶控件的關(guān)鍵代碼:
SystemVersion.ascx

復(fù)制代碼 代碼如下:


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SystemVersion.ascx.cs" Inherits="UserControls_SystemVersion" %>
<!-- Value是傳入的值 -->
<div>
<asp:DropDownList runat="server">
</asp:DropDownList>
</div>


后臺文件:

復(fù)制代碼 代碼如下:


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;
}
}
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 平谷区| 建德市| 襄汾县| 房山区| 钟祥市| 高邑县| 中宁县| 宿州市| 辽阳市| 涞水县| 邳州市| 美姑县| 扶余县| 西昌市| 泸水县| 云梦县| 揭阳市| 北流市| 竹山县| 霞浦县| 嘉兴市| 崇信县| 西宁市| 寿宁县| 太湖县| 故城县| 松溪县| 蓬安县| 清苑县| 固原市| 廊坊市| 鄂温| 莎车县| 应用必备| 桦南县| 高雄县| 祁门县| 商都县| 郸城县| 崇州市| 定结县|