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

hide/show edit command button based on another column

2 Answers 317 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesper Vognsen Laustsen
Top achievements
Rank 2
Jesper Vognsen Laustsen asked on 26 Aug 2010, 12:14 AM
Hi,

I have a Grid on a page, which contans a list of security gropus for my system. Some ot the groups are system groups and can not be altered. Each group have a bool GroupIsSystem group, placed in a column in the grid.

I would like to be able to hide the "Edit" command button on rows where column "GroupIsSystemGroup" is true, and show the edit button on opposite rows.

I know how to hook into ItemDataBound event, to do conditional formatting of my DataItem, I just cant figure out how to get to the row instance of the "Edit" button and set it to Visible = false.

Sincerely....

Jesper Laustsen

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Aug 2010, 05:10 AM
Hello Jesper,

You can hide the EditButton by using following code snippet.

ASPX:
<telerik:GridEditCommandColumn UniqueName="EditColumn">
</telerik:GridEditCommandColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
   if (e.Item is GridDataItem)
    {
      GridDataItem dataItem = (GridDataItem)e.Item;
      if(. .) // check for condition
      (dataItem["EditColumn"].Controls[0] as LinkButton).Visible = false; //hiding edit button
    }
 }

Thanks,
Princy.
0
Jesper Vognsen Laustsen
Top achievements
Rank 2
answered on 26 Aug 2010, 06:41 AM
Thanks man - Oh I was so close... just forgot to assign the edit column a unique name, so I thought it may have some mysterious system name :-) lol

But the solution is obvious and just what I needed. Thanks.

Best regards..

Jesper
Tags
Grid
Asked by
Jesper Vognsen Laustsen
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Jesper Vognsen Laustsen
Top achievements
Rank 2
Share this question
or