repeater - How can I access the attributes of a <span> element inside of an asp.net RepeaterItem? -


i'm trying alter css class of span positioned within asp.net repeateritem. span element has other tags inside of (radio button).

the markup similar this:

<asp:repeater>     <itemtemplate>         <span class="spanclass" runat="server">             <label>                 <asp:radiobutton id="rbid">                 </asp:radiobutton>             </label>         </span>     </itemtemplate> </asp:repeater> 

i'm able edit radio button using following:

rb = (radiobutton)(repeateritem.findcontrol("rbid"); rb.checked = true; //this works 

however, when using similar piece of code grab span, fails innerhtml exception because span not literal control:

span = (generichtmlcontrol)(repeateritem.findcontrol("spanid"); span.attributes.add("class", "classtoadd"); //this fails 

the reading i've done says case because span not literal control because has other server controls within (the radio button).

is there way access attributes of <span> in question?

change span this:

<span id="spanid" runat="server"> 

and in code behind:

protected void myrep_itemdatabound(object sender, repeateritemeventargs e) {     if (e.item.itemtype == listitemtype.item)     {         htmlgenericcontrol x = (htmlgenericcontrol)e.item.findcontrol("spanid");         x.attributes["class"] = "myclass";     }  } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -