开发者

ASP.net c# change pannel class

开发者 https://www.devze.com 2023-01-10 15:45 出处:网络
<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"admin.aspx.cs\" Inherits=\"******._Default\"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="admin.aspx.cs" Inherits="******._Default"
    title="Administration"
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
    1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="mainHead" runat="server" >
        <title>Administration</title>
        <link rel="Stylesheet" href="../style/admin.css" />       
    </head>
    <body>

    <div class="topMenu">    

        <asp:Panel id="mnu0" runat="server" class="navButton">
            <a href="admin.aspx" class="navLink">Admin Home</a>
        </asp:Panel>

        <asp:Panel id="mnu1" runat="server" class="navButton">
            <a href="admin.aspx" class="navLink">User Manager</a>
        </asp:Panel>

        <asp:Panel id="mnu2" runat="server" class="navButton">
            <a href="admin.aspx" class="n开发者_C百科avLink">Products</a>
        </asp:Panel>  

    </div>

    <br /><br />
    <div class="subMenu">
        <a href="products.aspx" class="subLink">Products</a> <a href="productCats.aspx" class="subLink">Categories</a> 
    </div>

    <br /><br />
    Welcome to the Admin

    </body>
</html>

Code behind:

public partial class _Default : System.Web.UI.Page { protected int menuID;

protected void Page_Load(object sender, EventArgs e)
{

    string menuIDdata = Page.Request.QueryString["mid"];
    menuID = 0;

    // Check the user is allowed here
    if (!Roles.IsUserInRole("Admin"))
    {
        Response.Redirect("../default.aspx");
    }

    // Get the menu ID
    if (int.TryParse(menuIDdata, out menuID))
    {
        menuID = int.Parse(menuIDdata);
    }
    else
    {
        menuID = 0;
    }

    mnu0.CssClass = "navButtonO";

}   

}

I'm trying to change the class of the menu depending on which one is selected, but is there an elegant way to change the class instead of a switch/if statement? For example:

mnu[menuID].CssClass = "navButtonO";

Would change the class of the menu item.


Try:

var panel = this.Page.FindControl(menuId) as Panel;
panel.CssClass = "navButtonO";
0

精彩评论

暂无评论...
验证码 换一张
取 消