asp.net 用户控件读取以及赋值
2009-07-18 00:00
806 查看
XML内容如下:
用户控件的关键代码:
SystemVersion.ascx
后台文件:
<?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; } } }
相关文章推荐
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法
- 转:ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法
- ASP.NET读取DLL文件中的页面和用户控件(VirtualPathProvider VirtualFile)
- ASP.NET MVC加载用户控件后并获取其内控件值或赋值
- asp.net读取用户控件,自定义加载用户控件
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法
- ASP.NET web的自定义用户控件以及相关问题
- 农民伯伯--关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- asp.net page中用ViewState读取用户控件中的属性
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- asp.net MVC _LayOut布局以及用户控件的使用
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验