c# - How to change button text on page load based on listview value on Visual Studio -
i want change button text on page load after retrieving list view values.
for example,
<asp:label id="favouritelabel" runat="server" text='<%# eval("favourite") %>' />
if label value 1, button change favourited.
i have retrieved list view values binding listview
protected void listview1_itemdatabound(object sender, listviewitemeventargs e) { if (e.item.itemtype == listviewitemtype.dataitem) { label activity = (label)e.item.findcontrol("favouritelabel"); activityid = activity.text; } }
then, activityid , simple if-else check on page load
protected void page_load(object sender, eventargs e) { if (activityid == "1") { button4.text = "favourited"; } else { button4.text = "favourite"; } }
however not work. anybody?
do inside postback check in load event, instance:
protected void page_load(object sender, eventargs e) { if (!ispostback) { if (activityid == "1") { button4.text = "favourited"; } else { button4.text = "favourite"; } } }
read more postback here
Comments
Post a Comment