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

[Solved] Can't hide edit column without Insert row being affected

1 Answer 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 03 Nov 2009, 08:06 PM

My problem is I want to hide the edit column in my RadGrid and only show the "Delete" column and at the bottom a link to let the user insert or add a new record. If I do not hide the edit column then click my command button to show the insert code it works fine and I see an Insert and Cancel link. However, if I add visible = "false" to the GridEditCommandColumn like this:

<telerik:GridEditCommandColumn Visible="true" />

then all of a sudden my Insert and Cancel buttons disappear when in insert mode yet the form field is still there. I have also tried to hide the column programmatically in PreRender but the same thing happens. Please advise on how to hide the edit column without affecting the insert functionality.

<telerik:RadGrid ID="myGrid" runat="server"   
                    OnInsertCommand="myGrid_OnInsertCommand"                      
                    OnNeedDataSource="myGrid_OnNeedDataSource" 
                    OnDeleteCommand="myGrid_OnDeleteCommand"                      
                    OnColumnCreated="myGrid_OnColumnCreated"   
                    OnPreRender="myGrid_PreRender1" 
                    Width="500px" AutoGenerateDeleteColumn="True" AllowFilteringByColumn="True" AutoGenerateColumns="False" 
                    GridLines="None">  
                  
                    <MasterTableView DataKeyNames="PhoneNumber" EditMode="InPlace" InsertItemDisplay="Bottom" 
                        CommandItemDisplay="Bottom">  
                        <RowIndicatorColumn> 
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn> 
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="PhoneNumber" HeaderText="Phone Number" UniqueName="PhoneNumber">  
                            </telerik:GridBoundColumn>                        
                            <telerik:GridEditCommandColumn Visible="false"  />                            
                        </Columns> 
                        <EditFormSettings> 
                            <EditColumn UniqueName="EditCommandColumn1"  > 
                            </EditColumn> 
                        </EditFormSettings> 
                        <CommandItemTemplate> 
                            <div style="padding: 3px;">  
                                <asp:ImageButton ID="addNewPhonelistImg" runat="server" ImageUrl="add.gif" CommandName="InitInsert" /> 
                                <asp:LinkButton CommandName="InitInsert" ID="addNewPhonelist" Text="Insert New Phone Number" 
                                    runat="server" Font-Size="Small" /> 
                            </div> 
                        </CommandItemTemplate> 
                    </MasterTableView> 
                    <FilterMenu> 
              
                    </FilterMenu> 
                </telerik:RadGrid> 
                     

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Nov 2009, 08:11 AM
Hello Adam,

When using Inplace editmode, you need to have the EditCommandColumn displayed inorder to show the insert and cancel buttons. If you want to hide the EditCommandColumn but still display the insert and cancel buttons, then you can either use EditForms OR use the following code to conditionally hide the EditCommandColumn:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
   { 
       if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            RadGrid1.MasterTableView.GetColumn("EditCommandColumnUniqueName").Visible = true
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items) 
            { 
                ((LinkButton)dataItem["EditCommandColumnUniqueName"].Controls[0]).Visible = false
            } 
        } 
        else 
        { 
            RadGrid1.MasterTableView.GetColumn("EditCommandColumnUniqueName").Visible = false
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or