最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2009年07月18日 11:30:39   作者:  
最近項(xiàng)目中看到同事寫的一個(gè)用戶控件,是一個(gè)下拉,值是從XML中讀取的,而且這部分還用到了LINQ讀取XML的知識,最近才看了一點(diǎn)點(diǎn)LINQ的知識,當(dā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 style="white-space:nowrap">
<asp:DropDownList ID="ddlVersion" 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;
}
}
}

相關(guān)文章

最新評論

东海县| 朝阳区| 咸阳市| 麻江县| 疏勒县| 高唐县| 饶阳县| 绥宁县| 明溪县| 大邑县| 军事| 兴山县| 平塘县| 涪陵区| 夏津县| 德清县| 河间市| 铜山县| 临猗县| 措美县| 循化| 河池市| 海口市| 饶平县| 田林县| 昂仁县| 交口县| 全州县| 依兰县| 白水县| 怀柔区| 蚌埠市| 石河子市| 化德县| 吉安市| 彰化市| 仁布县| 马龙县| 伊金霍洛旗| 太谷县| 乃东县|