c# - Grab a List Item from the Master Page -
i have listitem
in master
page need assign new css class
.
<ul> <li></li> <li id="myli" runat="server"></li> <li></li> </ul>
the first thing tried following:
listitem li = this.master.findcontrol("myli");
cannot implicitly convert type 'system.web.ui.control' 'system.web.ui.webcontrols.listitem'
then:
listitem li = (listitem) this.master.findcontrol("myli");
cannot convert type 'system.web.ui.control' 'system.web.ui.webcontrols.listitem'
then:
control li = this.master.findcontrol("myli");
but didn't find method give new css class.
sounds need grab webcontrol
rather control
. solution?
you need cast htmlgenericcontrol
, this:
htmlgenericcontrol li = (htmlgenericcontrol)this.master.findcontrol("myli");
the htmlgenericcontrol
has attributecollection
property can use:
li.attributes.add("class", "myclass");
Comments
Post a Comment