Hide Edit Link Based on Condition

2 posts, 1 answers
  1. L
    L avatar
    298 posts
    Member since:
    Apr 2008

    Posted 09 Mar 2016 Link to this post



    How should i hide Edit link based on Permission Type. For example, if PermissionType is User then i want to hide the Edit link in the grid. Here is my code.


     <telerik:GridBoundColumn DataField="PermissionType" FilterControlAltText="Filter PermissionType column" HeaderText="Type" SortExpression="PermissionType" UniqueName="PermissionType">
                                <ModelErrorMessage Text="" />
                          <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="editcolumn" FilterControlAltText="Filter column column" ItemStyle-ForeColor="Blue" ItemStyle-Font-Underline="true" HeaderText="Edit" Text="Edit" 
                            UniqueName="editcolumn" >                        
                            <ItemStyle Font-Underline="True" ForeColor="Blue"></ItemStyle>


    Thanks a lot

  2. Answer
    Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 11 Mar 2016 Link to this post


    For conditionally hide the Edit LinkButton depending on the PersmissionType value you can handle the OnItemDataBound event and use the following code for hiding the button for "User" type:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        if (e.Item is GridDataItem)
            GridDataItem item = e.Item as GridDataItem;
            (item["editcolumn"].Controls[0] as LinkButton).Visible = item["PermissionType"].Text != "User";

    Hope this helps.

    Konstantin Dikov
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top