<asp:DropDownList ID="ddlSkin" runat="server" AutoPostBack="True">
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>gvFirstSkin</asp:ListItem>
<asp:ListItem>gvSecondSkin</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="gvCatalog" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDSCatalog">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="ParentID" HeaderText="ParentID"
SortExpression="ParentID" />
<asp:BoundField DataField="OrderBy" HeaderText="OrderBy"
SortExpression="OrderBy" />
<asp:BoundField DataField="UrlID" HeaderText="UrlID" SortExpression="UrlID" />
</Columns>
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDSCatalog" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLCONNECTIONSTRING %>"
SelectCommand="SELECT * FROM [Catalog]"></asp:SqlDataSource>
</p>
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["ddlSkin"] != null)
{
Theme = Request["ddlSkin"].ToString(); //获取当前选择主题
if (Theme == "None")
{
Theme = "";
gvCatalog.SkinID = "";
}
if (Theme != string.Empty)
{
gvCatalog.SkinID = Theme.Substring(2);
}
}
}
主题是在Page_PreInit(object sender, EventArgs e)事件触发之后立即加载的。因此,如果要动态加载页面的主题,那么至少要在事件Page_PreInit之前动态修改页面主题。