Apply CSS for an HTML generic control like <UL> and <LI> in ASP.NET
23,649
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:
make new blank master page and put <ul runat="server" id="ull">
then add a new page and use the above master page.
make findcontrol ul and put in CSS as I have mentioned in the answer.
then run your page, and view source of your HTML page and you will find what you are looking for. Like
Author by
ACP
Updated on August 11, 2022Comments
-
ACP over 1 year
I don't know how to apply CSS for a HTML generic control like
<UL>
and<LI>
givenrunat="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>
-
ACP over 14 yearsHai Akthar, I use find control to find a list named "home" like this Control list = this.Master.FindControl("mainMenu").FindControl("mainHome"); now how to aplly css for the control list....