Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET: Setting the Style of an HTML element Programatically
    primarykey
    data
    text
    <p>I'm generating a menu with a Repeater control bound to an XmlDataSource. </p> <pre><code>&lt;asp:Repeater ID="myRepeater" runat="server" DataSourceID="myDataSource" onitemdatabound="myRepeater_ItemDataBound" onitemcreated="myRepeater_ItemCreated"&gt; &lt;HeaderTemplate&gt; &lt;ul class="menu_list"&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;li id="liMenu" runat="server"&gt;&lt;asp:HyperLink ID="hrefMenuItem" runat="server" Text='&lt;%# XPath("@text")%&gt;' NavigateUrl='&lt;%# XPath("@href")%&gt;'&gt;&lt;/asp:HyperLink&gt;&lt;/li&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;/ul&gt; &lt;/FooterTemplate&gt; &lt;/asp:Repeater&gt; &lt;asp:XmlDataSource runat="server" ID ="myDataSource" XPath="Menu/Items/*" EnableCaching="False" /&gt; </code></pre> <p>I'd like to be able to set the style of the containing LI based on mouseover events and currently selected menu item. I tried via the HtmlGenericControl, but I receive an error that it's readonly.</p> <pre><code>protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { HyperLink hrefCurrentMenuLink = e.Item.FindControl("hrefMenuItem") as HyperLink; HtmlGenericControl l_genericControl = e.Item.FindControl("liMenu") as HtmlGenericControl; if ((hrefCurrentMenuLink != null) &amp;&amp; (l_genericControl != null)) { string l_currentPage = GetCurrentWebPage(); if (String.Compare(Path.GetFileNameWithoutExtension(hrefCurrentMenuLink.NavigateUrl), l_currentPage, StringComparison.OrdinalIgnoreCase) == 0) l_genericControl.Style = "on-nav"; else l_genericControl.Style = "off-nav"; l_genericControl.Attributes.Add("onmouseover", "navOn(this)"); l_genericControl.Attributes.Add("onmouseout", "navOff(this)"); } } } </code></pre> <p>Is there any way to accomplish this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload