Thursday, 15 April 2010

c# - Find and change a specific item in Repeater -



c# - Find and change a specific item in Repeater -

i have next <asp:repeater>:

<asp:repeater id="repmenuparent" runat="server" datasourceid="odsmenuparent" onitemcommand="repmenuparent_onitemcommand" onitemdatabound="repmenuparent_onitemdatabound" > <itemtemplate> <asp:button id="btnrepeaterparent" runat="server" skinid="btnagroquimicos" cssclass="celdasmenusdinamicas" text='<%# eval("nombre") %>' commandname='<%# eval("nombre") %>' /> </itemtemplate> </asp:repeater>

when commandevent triggered set session commandname , uniqueid:

protected void repmenuparent_onitemcommand(object source, repeatercommandeventargs e) { session.add("nombresubmenuagro", e.commandname); string id = e.item.uniqueid; session.add("souceid", id); }

the issue following: need alter forecolor of botton within repeater cicked user. in beginnig buttons (items in repeater) gray. when clicked need alter forecolor of reddish (like breadstuff crumb).

i've trying find item in itemdatabound , compare uniqueid doesn't work, don't know how find specific item clicked alter forecolor:

protected void repmenuparent_onitemdatabound(object sender, repeateritemeventargs e) { string sessionid = ""; button btnrepeater; if ((e.item.itemtype == listitemtype.item) || (e.item.itemtype == listitemtype.alternatingitem)) { btnrepeater = (button)e.item.findcontrol("btnrepeaterparent"); if (btnrepeater != null) { if(btnrepeater.uniqueid.equals(sessionid)) { btnrepeater.forecolor = system.drawing.color.fromargb(69, 187, 32); } } } }

i've read many blog's threads repeater , find it's items, can´t find solved issue, can help me please?

i think problem best solved javascript though have server side solution you.

the command event object has property called commandsource. gives access button triggered command event.

class="lang-cs prettyprint-override">protected void repmenuparent_onitemcommand(object source, repeatercommandeventargs e) { button btnrepeater=e.commandsource; btnrepeater.forecolor = drawing.color.red; }

c# asp.net repeater

No comments:

Post a Comment