如何根据C#中的当前焦点动态分配“is-active”类

时间:2013-09-12 18:55:47

标签: c# html css

我有一个名为“is-active”的类,它有一个彩色箭头,从导航到主要内容,根据哪个链接是当前活动链接。代码运行foreach并从数据库中提取所有类别。如何让“is-active”类仅显示当前链接?我知道它有效,因为我将它放在openList控件中并且它显示在所有五个类别上,我只是不知道如何让它仅在所选类别上显示。

提前感谢您的帮助!

以下是我的类别和链接按钮的代码:

protected override void CreateChildControls()
    {
        LiteralControl openingDiv = new LiteralControl("<div id='MainPanel'>");
        LiteralControl closingDiv = new LiteralControl("</div>");   

        this.Controls.Add(openingDiv);

        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            LiteralControl openList = new LiteralControl("<li class='" + dr["CategoryColor"].ToString() + "'>");
            LiteralControl closeList = new LiteralControl("</li>");                

            Label lblNumber = new Label();

            LinkButton myLinkButton = new LinkButton();

            myLinkButton.Text = "<span class='number'>" + dr["CategoryNumber"] + "</span>"+ dr["CategoryName"].ToString();
            myLinkButton.CommandArgument = dr["Category_ID"].ToString();
            myLinkButton.Click += myLinkButton_Click;

            this.Controls.Add(openList);
            this.Controls.Add(myLinkButton);
            this.Controls.Add(closeList);
        }
        this.Controls.Add(closingDiv);
    }
    void myLinkButton_Click(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)(sender);
        Session["CategoryID"] = btn.CommandArgument;

        Response.Redirect(Request.RawUrl);  
    }

0 个答案:

没有答案