问题描述
大家好,
我想找到一个 UL 控件,然后在该 UL 中找到一个 LI,并从内容页面为其分配一个 css 类....
I want to find a UL control and then find a LI within that UL and assign a css class to that from a content page....
<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>
如果用户点击主页,它会被重定向到 users.aspx 页面,我想用颜色突出显示主页 LI...请给我建议...
If the user clicks home it is redirected to users.aspx page and i want to highlight Home LI with a color... Plz give me suggestion...
推荐答案
如果我理解正确的话......
If I have understood this correctly...
如果您的列表在母版页上...
If your list is on the master page...
<ul runat="server" id="list">
<li runat="server" id="home">Home</li>
<li runat="server" id="news">News</li>
</ul>
...那么您可以在内容页面上执行此操作...
...then you can do this on your content page...
Control list = this.Page.Master.FindControl("list");
然后 li 对象将成为列表对象中的控件 - 例如list.Controls
.或者你可以这样做......
Then the li objects will be controls in the list object - e.g. list.Controls
. Or you can do...
Control home = this.Page.Master.FindControl("list").FindControl("home");
...查找列表控件的具体控件.
...to find specific controls of the list control.
在 HTML 控件上使用 runat="server" 时,服务器端等效对象将为 HtmlGenericControl.
When using the runat="server" on the HTML controls the server side equivalent object will be HtmlGenericControl.
如果你想为 LI 标签应用一个类,你需要做的是将 LI 对象转换为 HtmlGenericControl 和然后使用 Attributes 属性.比如……
If you want to apply a class to the LI tags what you would have to do is cast the LI object to a HtmlGenericControl and then use the Attributes property. For example...
HtmlGenericControl home = (HtmlGenericControl)this.Page.Master.FindControl("list").FindControl("home");
home.Attributes["class"] = "className";
希望对您有所帮助...
Hope that helps...
这篇关于查找 UnorderedList <UL>从 asp.net 中的内容页控制母版页内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!