This is a migrated thread and some comments may be shown as answers.

Hide Edit Link Based on Condition

1 Answer 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 09 Mar 2016, 01:10 PM

hi

 

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">
                        <ColumnValidationSettings>
                            <ModelErrorMessage Text="" />
                        </ColumnValidationSettings>
                    </telerik:GridBoundColumn>
                      <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>
                    </telerik:GridButtonColumn>

 

Thanks a lot

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 11 Mar 2016, 02:50 PM
Hi,

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.


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or