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

Hiding GridEditCommandColumn

7 Answers 552 Views
Grid
This is a migrated thread and some comments may be shown as answers.
The KID
Top achievements
Rank 2
The KID asked on 15 Jul 2008, 08:53 PM
Does anyone know at what point the GridEditCommandColumn is rendered? I need to be able to hid the column on the page load given certain conditions and nothing that i've tried, i never can find the control. I can find other controls such as grid data item and template items, but not the GridEditCommandColumn items.

Thanks

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Jul 2008, 04:23 AM
Hello Mike,

According to what i understood,  the code snippet below  hides the GridEditCommandColumn on PageLoad.

CS:
protected void Page_Load(object sender, EventArgs e) 
    { 
        foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (column.ColumnType == "GridEditCommandColumn") 
            { 
                GridEditCommandColumn editcol = (GridEditCommandColumn)column; 
                editcol.Display = false
            } 
        } 
    } 

Thanks
Princy.

0
The KID
Top achievements
Rank 2
answered on 16 Jul 2008, 06:40 PM
Thanks for the help. Do you know what i'd need to do to also hide items in the CommandItemTemplate? What I'd doing in this project is some people i want to allow them to add/edit the grid and other i want to hide that ability. So i have columns to add/edit as well buttons in the CommandItemTemplate.

Thanks
0
Princy
Top achievements
Rank 2
answered on 17 Jul 2008, 05:01 AM
Hi Mike,

You can hide the CommandItem in the code behind as shown below.

CS:
 RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; 


Thanks
Princy.
0
The KID
Top achievements
Rank 2
answered on 05 Aug 2008, 10:23 PM
Maybe I haven't explained myself correctly. I need to do on a row by row basis. One row i want to hide the button the next i want to show the button. Should I be trying in the ItemCreate event or the ItemDataBound?
0
The KID
Top achievements
Rank 2
answered on 05 Aug 2008, 10:51 PM
This is what you need to do:

protected void rgMain_ItemDataBound(object source, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            ImageButton imgbtn = (ImageButton)item["EditColumn"].Controls[0]; 
            imgbtn.Visible = false
        } 
    } 

0
Yavor
Telerik team
answered on 06 Aug 2008, 05:15 AM
Hello Mike,

Indeed, this is the correct approach. You may also consider moving the code in the PreRender event handler, and iterating through all the items in the grid (foreach gridDataItem dataItem in RadGrid1.MasterTableView.Items), since the ItemDataBound may not be called on each page cycle. Other than that, the inner code remains the same.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 2
answered on 06 Aug 2008, 07:30 AM
Hi Mike,

You may also be interested to see the following help article which explains how to achieve conditional image display in GridButtonColumn.
Conditional image display in GridButtonColumn/GridTemplateColumn

Regards
Shinu.
Tags
Grid
Asked by
The KID
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
The KID
Top achievements
Rank 2
Yavor
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or