开发者

Hiding a LinkButton in DataList

开发者 https://www.devze.com 2022-12-30 16:02 出处:网络
Hi someone can tell me how to hide a LinkButton inside a DataList? I\'ve tried to do this but I 开发者_StackOverflow社区do not work:

Hi someone can tell me how to hide a LinkButton inside a DataList?

I've tried to do this but I 开发者_StackOverflow社区do not work:

 protected void Page_PreRender(object sender, EventArgs e)
    {


        foreach (var item in listanews)
        {
            DataList container = dlgestionenews;
            if (string.IsNullOrEmpty(item.IdNews))
            {

                DataListItem itemdatalist = null;


                foreach (DataListItem itemdl in container.Items)
                {

                    foreach (Control control in itemdatalist.Controls)
                    {

                        if (control.GetType().FullName == "LinkButton")
                        {
                            ((LinkButton)control).Visible = false;

                        }

                    }
                }

            }
        }
    }

Thanks!


Try this:

foreach (DataListItem dli in yourDataListControl.Items)
{
    LinkButton lbLinkButton = (LinkButton)dli.FindControl("yourLinkButtonID");
    if (lbLinkButton != null)
    {
         lbLinkButton.Visible = false;
    }
}


You should move this code to the

protected virtual void OnItemDataBound(
    DataListItemEventArgs e
)

event. In this event, you should use the e.Item.FindControl('LinkButtonID') method for the finding your control

More info is here

0

精彩评论

暂无评论...
验证码 换一张
取 消