0
votes

I have a gridview which contains few Template columns, In the first Template column , I have a LinkButton (Visible bydefault) and a Label(Hidden bydefault).

I have setup a property (IsPopup) on server side (aspx.cs file)

Now my requirement is to Show LinkButton and hide Label if IsPopup is true and vice versa.

Following is the code sample

aspx.cs code

public bool IsPopup
{
  get;
  set;
}

aspx code

 <asp:GridView ID="gvEquipment" runat="server" AutoGenerateColumns="False" >

   <Columns>
     <asp:TemplateField HeaderText="ID" meta:resourcekey="TemplateFieldResource2">
       <ItemTemplate>
         <asp:Label ID="lblCheckPointCode" runat="server" meta:resourcekey="lblCheckPointCodeResource1"
           Text='<%# Bind("CheckPointCode") %>' Visible="False"></asp:Label>
         <asp:LinkButton ID="lbtnCheckPointCode" runat="server" CausesValidation="False" CommandName="Edit"
           meta:resourcekey="lbtnCheckPointCodeResource1" Text='<%# Bind("CheckPointCode") %>'></asp:LinkButton>
       </ItemTemplate>
       <ItemStyle Width="25%" />
     </asp:TemplateField>

   </Columns>

 </asp:GridView>

In the above code you can see the Label is visible false bydefault.

When I tried to implement Visible='<# IsPopup '

following error appears: Parser Error Message: Cannot create an object of type 'System.Boolean' from its string representation '<# IsPopup ' for the 'Visible' property.

2

2 Answers

1
votes

Try this :

    <asp:Label ID="lblCheckPointCode" runat="server" meta:resourcekey="lblCheckPointCodeResource1"
       Text='<%# Bind("CheckPointCode") %>' Visible='<%# IsPopup '></asp:Label>
     <asp:LinkButton ID="lbtnCheckPointCode" runat="server" CausesValidation="False" CommandName="Edit"
       meta:resourcekey="lbtnCheckPointCodeResource1" Text='<%# Bind("CheckPointCode") %>' Visible='<%# !IsPopup '></asp:LinkButton>

[Edit] another approach, you can handle the RowCreated Event :

void ProductsGridView_RowCreated(Object sender, GridViewRowEventArgs e)
{    
    var lbl = e.Row.FindControl("lblCheckPointCode");
    if(lbl != null) lbl.Visible = !IsPopup;

    var lnk= e.Row.FindControl("lbtnCheckPointCode");
    if(lnk!= null) lbl.Visible = !IsPopup;



}
0
votes

Use Visible='<%# Bind("IsPopup ") %>' to set visible true or false of control.