0

I'm using a LinkButton in Repeater ItemTemplate but if my LinkButton is NULL then I don't want to show this Linkbutton. Can I control this LinkButton on Page Load?

<asp:Repeater ID="rptSlider" runat="server" >
     <ItemTemplate>
        <li>
           .....
               <asp:LinkButton ID="lb_url" PostBackUrl='<%#Eval("button_url") %>' runat="server">Go</asp:LinkButton>
            ...
        </li>
     </ItemTemplate>

Nilgün
  • 51
  • 2
  • 8

2 Answers2

1

Try this way in page-load event

LinkButton linkButton= (LinkButton)Repeater1.Items[0].FindControl("lb_url");
linkButton.Visible = false;

but I will suggest to use ItemDataBound event to set visibility of link-button.

protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item ||
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var linkButton= e.Item.FindControl("lb_url") as LinkButton;
      // set link-button visibility 
    }
}
111
  • 1,779
  • 1
  • 12
  • 15
0

You may check the same under ItemCommand. Please check whether the following code works or not.

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    string url=((LinkButton)e.CommandSource).Text;

    if (string.IsNullOrEmpty(url))

        ((LinkButton)e.CommandSource).Visible=false;
    else

         ((LinkButton)e.CommandSource).Visible=true; 

}
Shyju
  • 203
  • 1
  • 5