Saturday, 15 May 2010

asp.net - Making a specific label in a repeater visible after binding -



asp.net - Making a specific label in a repeater visible after binding -

i'm trying create specific label in repeater visible after binding. don't want labels of every items in repeater visible. 1 click button. when click button update i'm updating info tourney item in db want show label alter success item updated.

here's code behind. [...] update in db

protected void repeattourney_itemcommand(object source, repeatercommandeventargs e) { if (e.commandname == "btnupdate_click") { [...] label lblsuccess= (label)e.item.findcontrol("lblupdatesuccess"); bindrepeater(ddlevents.text); lblsuccess.visible = true; } }

here's aspx. [...] textboxes , other stuff contains info db item.

<asp:repeater id="repeattourney" runat="server" onitemdatabound="repeattourney_itemdatabound" onitemcommand="repeattourney_itemcommand"> <itemtemplate> <div class="form"> [...] <asp:label id="lblupdatesuccess" runat="server" text="update success" visible="false" /> <asp:button id="btnupdate" runat="server" text="update" cssclass="button" commandname="btnupdate_click" /> [...] </div> </itemtemplate> </asp:repeater>

in end should this

item info btnupdate lblsuccess.visible = false item info btnupdate <== clicked lblsuccess.visible = true

thank help provided.

edit : here's bindrepeater code

private void bindrepeater(string name) { list<tourney> list = tourneydal.getbynameevent(name); [...] repeattournois.datasource = list; repeattournois.databind(); [...] }

edit 2 : give thanks thought of id tell 1 need visible after binding.

worked fine. :)

here new code

private void bindrepeater(string name, int index) { list<tourney> list = tourneydal.getbynameevent(name); [...] repeattourney.datasource = list; repeattourney.databind(); [...] if (index != 0) { label lblreussie = (label)repeattourney.items[index].findcontrol("lblupdatesuccess"); lblsuccess.visible = true; } protected void repeattourney_itemcommand(object source, repeatercommandeventargs e) { if (e.commandname == "btnupdate_click") { [...] label lblsuccess= (label)e.item.findcontrol("lblupdatesuccess"); bindrepeater(ddlevenements.text, e.item.itemindex); lblsuccess.visible = true; } } }

you haven't said what's going wrong, exception?

you utilize itemdatabound set visibility. hence have store index/id have updated last, e.g in field:

protected void repeattourney_itemcommand(object source, repeatercommandeventargs e) { if (e.commandname == "btnupdate_click") { updatedid = int.parse(e.commandargument.tostring()); bindrepeater(ddlevents.text); } } private int? updatedid = null; protected void repeattourney_itemdatabound(object sender, repeateritemeventargs e) { if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem) { var tourney = (tourney) e.item.dataitem; label lblupdatesuccess = (label)e.item.findcontrol("lblupdatesuccess"); lblupdatesuccess.visible = updatedid.hasvalue && tourney.id == updatedid.value; } }

asp.net repeater

No comments:

Post a Comment