c# - Setting visibility of a link in code behind -
c# - Setting visibility of a link in code behind -
i have in source code:
<a href="createalbum.aspx" id="createalbumlink"> create new album </a>
now want set visibility in code behind. how can so? have link within listview control. replaced above
<asp:linkbutton id="linkbutton1" runat="server" postbackurl="~/createalbum.aspx"> create new album1</asp:linkbutton>
still couldnt observe in codebehind.
source code:
<form id="form1" runat="server"> <asp:listview id="lvalbums" runat="server" datasourceid="sqldatasource1" groupitemcount="3" insertitemposition="lastitem"> <layouttemplate> <table border="1"> <tr id="groupplaceholder" runat="server"> </tr> </table> </layouttemplate> <grouptemplate> <tr> <td id="itemplaceholder" runat="server"> </td> </tr> </grouptemplate> <itemtemplate> <td id="td3" width="150px" height="150px" align="center" style="background-color: #e8e8e8;color: #333333;"> <asp:hiddenfield id="hfphotoid" runat="server" value='<%# eval("defaultphotid") %>' /> <a href='<%# "photos.aspx?albumid="+eval("albumid") %>'> <asp:image cssclass="timg" runat="server" id="imphoto" imageurl='<%# "thumbnail.ashx?imurl="+eval("photo") %>' /> </a> <br /> <b><asp:label id="lblalbumname" runat="server" text='<%# eval("albumname") %>'></asp:label> </b> </td> </itemtemplate> <insertitemtemplate> <td id="td3" width="150px" height="150px" runat="server" align="center" style="background-color: #e8e8e8;color: #333333;"> <asp:linkbutton id="linkbutton1" runat="server" postbackurl="~/createalbum.aspx"> create new album1</asp:linkbutton> <%-- <a href="createalbum.aspx" id="createalbumlink" runat="server"> create new album </a>--%> </td> </insertitemtemplate> </asp:listview> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:sliitcomdbconnectionstring %>" selectcommand="select album.albumid, album.defaultphotid, album.albumname, photalbum.photo album inner bring together photalbum on album.defaultphotid = photalbum.photoid album.userid=@userid"> <selectparameters> <asp:querystringparameter name="userid" type="int32" querystringfield="id" /> <%--<asp:sessionparameter name="userid" type="string" sessionfield="userid" />--%> </selectparameters> </asp:sqldatasource> </form>
well can't access linkbutton
straight since within listview
, can iterate through each item in listview , find link button using findcontrol
, set visible property. like:
foreach (listviewitem item in listview.items) { linkbutton linkbutton = item.findcontrol("linkbutton1") linkbutton; if (linkbutton != null) linkbutton.visible = false; }
the above disable linkbutton
items.
c# asp.net
Comments
Post a Comment