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
精彩评论