简体   繁体   English

asp:TableRow设置可见属性不起作用

[英]asp:TableRow set visible property not working

I'm working on a .NET 3.5 web application which shows/hides table rows contained in ascx files via an interface implementation (the controls containing the table implement the interface). 我正在使用.NET 3.5 Web应用程序,该应用程序通过接口实现(包含表的控件实现接口)来显示/隐藏ascx文件中包含的表行。

So, given this markup in the .ascx: 因此,鉴于.ascx中的此标记:

<asp:Table id="MyTable" runat="server">
<asp:TableRow ID="Foo" runat="server">
        <asp:TableCell ID="FooCell"
            runat="server"  ColumnSpan="3">
            //Cell contents omitted
        </asp:TableCell>
<asp:TableCell .... ellided
    </asp:TableRow>
</asp:Table>

The interface: 界面:

public interface IMyInterface
{
    Table GetPageDataTable();
}

The implementation in the ascx's code behind: 在ascx的代码后面实现:

#region IMyInterface Members

    public Table GetPageDataTable()
    {
        return MyTable;
    }

    #endregion

When I use a method like the one below from the containing page, as I loop through the table rows, the contains statement returns true however, the row's Visible property = false. 当我使用以下包含页面中的方法时,当我遍历表行时,contains语句返回true,但是,该行的Visible属性= false。

private void SetVisibleRows(IMyInterface control)
    {
        // the list stored in session contains 'Foo'
        List<string> choices = (List<string>)Session["selectionsList"]; 

        Table tbl = control.GetPageDataTable();

        foreach (TableRow r in tbl.Rows)
        {
            //r.ID == 'Foo'
            r.Visible = choices.Contains(r.ID, StringComparer.OrdinalIgnoreCase);
        }             
  }

I've also tried this directly in the control's codebehind, and even setting Foo.Visible = true; 我还直接在控件的代码后面尝试了此操作,甚至设置了Foo.Visible = true;。 still shows visible = false in the debug window. 在调试窗口中仍然显示visible = false。

Any help with this would be appreciated as it's driving me batty. 任何帮助,将不胜感激,因为它推动了我的发展。 I have another control which implements the interface and it's working fine for that one. 我还有另一个控件,它实现了该接口,并且对于那个接口来说,它工作正常。

Thanks! 谢谢!

I figured this out, and thought I'd share the answer. 我想通了,以为我会分享答案。

The call to SetVisibleRows needs to occur on the Page's OnLoadComplete Event. 对SetVisibleRows的调用需要在页面的OnLoadComplete事件上进行。 Trying to set row visibility before the control loads won't work. 尝试在控件加载之前设置行可见性将不起作用。

Thanks Tim, for your response. 感谢蒂姆的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM