嗨,有人能告诉我如何在DataList中隐藏一个LinkButton吗?
我试过这样做,但我不工作:
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;
}
}
}
}
}
}谢谢!
发布于 2010-05-19 20:06:23
试试这个:
foreach (DataListItem dli in yourDataListControl.Items)
{
LinkButton lbLinkButton = (LinkButton)dli.FindControl("yourLinkButtonID");
if (lbLinkButton != null)
{
lbLinkButton.Visible = false;
}
}发布于 2010-05-19 20:03:34
您应该将此代码移动到
protected virtual void OnItemDataBound(
DataListItemEventArgs e
)事件。在这种情况下,应使用e.Item.FindControl('LinkButtonID')方法查找控件
更多信息请访问here
https://stackoverflow.com/questions/2865215
复制相似问题