how to hide a linkbutton onload in asp.net

I have a linkbutton inside a listview.I want to know how can i hide this linkbutton on certain conditions.

My Codes

<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" OnClientClick="return deleteConfirm();">    
   <img src="../Admin/Images/deletebtn.png"alt="deletebtn"  class="deleteimgbtn" id="dltbtn"/>
  </asp:LinkButton> 

protected void Page_Load(object sender, EventArgs e)
     {
       ListView1.FindControl("LinkButton1").Visible = false;//Iam tried by using this code,but doesn't work
     }

Answers


When defining your ListView template, it is just that ... a template, so the buttons don't yet exist. You will therefore need to use the ListView.ItemDataBound event to find and disable your button as each item is being bound.

<asp:ListView ID="MyListView" runat="server" OnItemDataBound="MyListView_ItemDataBound">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" OnClientClick="return deleteConfirm();">    
            <img src="../Admin/Images/deletebtn.png"alt="deletebtn"  class="deleteimgbtn" id="dltbtn"/>
        </asp:LinkButton> 
    </ItemTemplate>
</asp:ListView>
protected void MyListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        var LinkButton1 = (LinkButton)e.Item.FindControl("LinkButton1");
        if (true) // insert your condition here
        {
            LinkButton1.Visible = false;
        }
    }
}

Need Your Help

Why can't i bind a DataGrid SelectedItem to a DependencyProperty Inside a usercontrol?

wpf mvvm user-controls dependency-properties

i want to bind a DataGrid SelectedItem inside a user control to a DependencyProperty

Type Native Wifi.Wlan + WlanReasonCode cannot be marshaled error

c# marshalling wlan

Wanted to ask your opinion on this error that I am getting while running my Wifi profile add code.