<div id="footer">
<p class="style1">
This site is not real.It is an example site for Core ASP.NET book.
</p>
</div>
</form>
</body>
</html>
Default2.aspx.cs :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string path = Server.MapPath("~/App_Themes");
if (Directory.Exists(path))
{
String[] themeFolders = Directory.GetDirectories(path);
foreach (String folder in themeFolders)
{
DirectoryInfo info = new DirectoryInfo(folder);
drpThemes.Items.Add(info.Name);
}
ListItem item = drpThemes.Items.FindByText(Page.Theme);
drpThemes.SelectedIndex = drpThemes.Items.IndexOf(item);
}
}
}
jack2006
Member
72 Points
219 Posts
how to load the CSS-code by a dropdownlist control?
Dec 25, 2007 01:28 PM|LINK
the code of Default2.aspx :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="container">
<div id="header">
<div id="themes">
<p>Theme <br />
<asp:DropDownList ID="drpThemes" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="drpTheme_selectedChanged"></asp:DropDownList>
</p>
</div>
<div id="bannerAd">
<asp:HyperLink ID="imgbtnAd" runat="server" />
</div>
<div class="clearBreak"></div>
<div id="logo" />
<asp:Image runat="server" ID="imgLogo" SkinID="logo" ImageUrl="~/images/cool.gif" />
</div>
</div>
<div id="sideArea">
<div id="masterMenu">
<asp:BulletedList ID="blstSample" runat="server">
<asp:ListItem Value="Default.aspx">Home</asp:ListItem>
<asp:ListItem Value="Products.aspx">Products</asp:ListItem>
<asp:ListItem Value="About.aspx">About</asp:ListItem>
</asp:BulletedList>
</div>
<div id="sideAreaBox">
<p>default side content</p>
</div>
</div>
<div id="mainArea">
<p>default main content</p>
</div>
<div id="footer">
<p class="style1">
This site is not real.It is an example site for Core ASP.NET book.
</p>
</div>
</form>
</body>
</html>
Default2.aspx.cs :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string path = Server.MapPath("~/App_Themes");
if (Directory.Exists(path))
{
String[] themeFolders = Directory.GetDirectories(path);
foreach (String folder in themeFolders)
{
DirectoryInfo info = new DirectoryInfo(folder);
drpThemes.Items.Add(info.Name);
}
ListItem item = drpThemes.Items.FindByText(Page.Theme);
drpThemes.SelectedIndex = drpThemes.Items.IndexOf(item);
}
}
}
protected void drpTheme_selectedChanged(object s, EventArgs e)
{
string theme = drpThemes.SelectedItem.Text;
Session["themeName"] = theme;
string page = Request.Path;
Server.Transfer(page);
}
public string AdImageUrl
{
get { return imgbtnAd.ImageUrl; }
set { imgbtnAd.ImageUrl = value; }
}
public string AdNavigateUrl
{
get { return imgbtnAd.NavigateUrl; }
set { imgbtnAd.NavigateUrl = value; }
}
}
It's the structure of the documents :81d47.jpg
As.NET2.0
Hong-Gang Ch...
All-Star
74696 Points
6768 Posts
Re: how to load the CSS-code by a dropdownlist control?
Dec 27, 2007 03:18 AM|LINK
Hi jack,
According to your requirement, I write a demo for your reference, see the demo:
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> public string CSS = ""; protected void Page_Load(object sender, EventArgs e) { CSS = "DropDownList1.SelectedValue.ToString()" + ".css"; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { CSS = DropDownList1.SelectedValue.ToString() + ".css"; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>List</title> </head> <body> <form id="form1" runat="server"> <div> <link href="<%= CSS %>" rel="stylesheet" type="text/css" /> <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Height="17px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="176px"> <asp:ListItem Selected="True">CSSOne</asp:ListItem> <asp:ListItem>CSSTwo</asp:ListItem> </asp:DropDownList> </div> </form> </body> </html>If you have any feedback about my replies,please contactmsdnmg@microsoft.com.
Microsoft One Code Framework