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

Hide GridBoundColumn on Editform

6 Answers 411 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 08 Jan 2010, 10:13 AM
Hi,

Here is a code snipped from my MasterTableView in my RadGrid.  When I clik on the edit hylperlink, I'd like to hide the txtLastName field and its label, so that noone knows it's there and no editing can happen to that field.  How can I do this in the code behind?

<Columns>    
        <telerik:GridEditCommandColumn UniqueName="editCommand"></telerik:GridEditCommandColumn>    
        <telerik:GridBoundColumn DataField="numPersonnelID" DataType="System.Int32"      
            HeaderText="Personnel ID" ReadOnly="True" SortExpression="numPersonnelID"      
            UniqueName="numPersonnelID" Visible="False">     
        </telerik:GridBoundColumn>    
        <telerik:GridBoundColumn DataField="txtLastName" HeaderText="Last Name"      
            SortExpression="txtLastName" UniqueName="txtLastName" MaxLength="50" Visible="false">     
        </telerik:GridBoundColumn>    
        <telerik:GridBoundColumn DataField="txtFirstName" HeaderText="First Name"      
            SortExpression="txtFirstName" UniqueName="txtFirstName" MaxLength="50">     
        </telerik:GridBoundColumn>    
</Columns> 

Thanks,
Greg


6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jan 2010, 10:37 AM
Hello Greg,

You can hide the column when grid is in editmode, using the following code snippet.

CS:
 
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        GridBoundColumn boundColumn = (GridBoundColumn)RadGrid1.MasterTableView.GetColumnSafe("companyName"); 
        if (e.CommandName == RadGrid.EditCommandName) 
        { 
            boundColumn.Visible = false
        } 
        else 
        { 
            boundColumn.Visible = true
        } 
    } 

Thanks,
Princy.
0
Greg
Top achievements
Rank 1
answered on 08 Jan 2010, 11:34 AM
Hi Princy,

Thanks for your quick response.

That works when the EditMode attribute for my MasterViewTable is set to "InPlace", but I'm currently using "EditForms".  Do you know how to accomplish the same thing using "EditForms".

Greg
0
Accepted
Martin
Telerik team
answered on 08 Jan 2010, 01:30 PM
Hello Greg,

You can try the following approach:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
        {
            (e.Item as GridEditableItem)["txtLastName"].Parent.Visible = false;
        }
    }

I hope this helps,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Greg
Top achievements
Rank 1
answered on 29 Jan 2010, 11:13 AM
It works.  Thank you.
0
Ratheesh
Top achievements
Rank 1
answered on 15 Jan 2014, 11:53 AM
how to visible false a particular gridboundcolumn in edit mode

0
Shinu
Top achievements
Rank 2
answered on 15 Jan 2014, 12:20 PM
Hi Ratheesh,

If you don't want a column to be in EditMode you can set its ReadOnly property to True, or else if you want to hide any column based on a condition you can handle it in the ItemDataBound event:

ASPX:
<telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID" ReadOnly="true">
</telerik:GridBoundColumn>

OR

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditableItem && e.Item.IsInEditMode)
   {
      GridEditableItem edit = (GridEditableItem)e.Item;        
      if (condition)
      {
          edit["ColumnUniqueName"].Parent.Visible = false;        
      }
   }
}

Thanks,
Shinu
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Greg
Top achievements
Rank 1
Martin
Telerik team
Ratheesh
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or