开发者

Apply CSS for an HTML generic control like <UL> and <LI> in ASP.NET

I don't know how to apply CSS for a HTML generic control like <UL> and <LI> given runat="server" in ASP.NET. I am finding the <li> in a master page from a content page. Once I found that control I want to apply CSS.

<ul id="mainMenu" runat="server" style="width:350px;">
    <li id="mainHome" runat="server"><a title="Home" href="#" class="home">Home</a></li>

    <li id="开发者_开发问答mainManage" runat="server"><a title="Manage" href="#"
                                          class="manage">Manage</a></li>

    <li id="mainEnquiry" runat="server"><a title="Enquiry" href="#"
                                           class="enquiry">Enquiry</a></li>

    <li id="mainReport" runat="server"><a title="Report" href="#"
                                          class="report">Reports</a></li>
</ul>


Please try this,

ull.Style.Add("background-color", "Red");

Or, I have tested this, will definitely work, please check

ull.Attributes.Add("class", "yourClass");

Edit: To test this solution I have provided you:

  1. make new blank master page and put <ul runat="server" id="ull">

  2. then add a new page and use the above master page.

  3. make findcontrol ul and put in CSS as I have mentioned in the answer.

  4. then run your page, and view source of your HTML page and you will find what you are looking for. Like

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜