Search code examples
asp.netaspxgridview

Hide item template in aspx page based on condition


I have following item template in my listview

<ItemTemplate>
    <asp:LinkButton ID="ibtnEdit" runat="server" Height="20px" Width="20px" ToolTip="Edit  this Category" CommandArgument='<%#  Eval("Category_ID")  %>' CommandName="EditObject"  CausesValidation="False"> <i class="glyphicon glyphicon-edit"></i>&nbsp;</asp:LinkButton> 
</ItemTemplate>

I want to hide this column based on following condition. This status field contain either 1 or 0.

<%#    Bind("Status") %>

I am not getting an idea how to do


Solution

  • I tried with following code and it works

     <asp:LinkButton ID="ibtnEdit" runat="server" Height="20px" Width="20px" ToolTip="Edit  this Category"
                            CommandArgument='<%#  Eval("Category_ID")  %>' Visible='<%# DecideHere((int)Eval("Status")) %>'  CommandName="EditObject"
                            CausesValidation="False"> <i class="glyphicon glyphicon-edit"></i>&nbsp;</asp:LinkButton> 
    

    In code behind

     protected bool DecideHere(int id)
                 {
                    if (id == 1 )
                        return true;
                    else
                        return false;
                 }