asp.net 用戶控件讀取以及賦值
<?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
<%@ 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>
后臺(tái)文件:
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)文章
ASP.NET下對(duì)cookies的操作實(shí)現(xiàn)代碼
ASP.NET下對(duì)cookies的操作實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-10-10.net core部署到windows服務(wù)上的完整步驟
這篇文章主要給大家介紹了關(guān)于.net core部署到windows服務(wù)上的完整步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.net core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09如何給ASP.NET Core Web發(fā)布包做減法詳解
在ASP.Net中可以使用打包與壓縮這兩種技術(shù)來提高Web應(yīng)用程序頁面加載的性能。下面這篇文章主要給大家介紹了關(guān)于如何給ASP.NET Core Web發(fā)布包做減法的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧2018-06-06FileUpload使用Javascript檢查擴(kuò)展名是否有效實(shí)現(xiàn)思路
在JavaScript獲取FileUpload控件的文件路徑,并取得路徑中的文件擴(kuò)展名,再與陣列中的擴(kuò)展名比較,如果存在,說明上傳的文件是有效的,反之無效,感興趣的朋友可以了解下,或許對(duì)你有所幫助2013-02-02.NET Core 2.0遷移小技巧之MemoryCache問題修復(fù)解決的方法
這篇文章主要給大家介紹了關(guān)于.NET Core 2.0遷移小技巧之MemoryCache問題修復(fù)解決的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08Global.asax取物理路徑/取絕對(duì)路徑具體方法
本文章來給大家簡(jiǎn)單介紹利用Global.asax取物理路徑和取絕對(duì)路徑代碼,有需要了解的朋友可參考參考2013-08-08在ASP.NET中,設(shè)置Session的過期時(shí)間的方法
在ASP.NET中,設(shè)置Session的過期時(shí)間的方法,需要的朋友可以參考下2012-12-12使用grpcui測(cè)試ASP.NET core的gRPC服務(wù)
這篇文章介紹了使用grpcui測(cè)試ASP.NET core gRPC服務(wù)的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07服務(wù)器讀取EXCEL不安裝OFFICE如何實(shí)現(xiàn)
用asp.net做了一簡(jiǎn)單的游戲管理后臺(tái),涉及到了上傳Excel導(dǎo)入數(shù)據(jù)的功能,在本地開發(fā)實(shí)現(xiàn)都好好的,可已上傳的服務(wù)器上就悲劇了,下面有個(gè)不錯(cuò)的解決方法,大家可以參考下2014-03-03