Search code examples
asp.netgridviewlabelvisible

Why does Visible='<%#false%>' work on a GridView but not label?


I am scratching my head over this, but have no idea what the problem is. My actual code is

<asp:Label ID="Label1" runat="server" Text="abc"
           Visible='<%#Request.QueryString["ListName"] == null %>' />
<asp:GridView ID="gvLists" runat="server"
              Visible='<%#Request.QueryString["ListName"] == null %>' />

As you can see, i am trying to only make the visibility of the object be driven by the querystring. It works fine for the GridView, but doesn't work for a label. I also tried Panel and HyperLink with the same results.

I am sure I could get this working by putting my code in the code-behind, but it won't be as clean.


Solution

  • Thanks to Alison for pointing me in the right direction. I needed to add Page.DataBind() to my Page_Load event in order for the expression to be evaluated.