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

Edit /Insert with popup and hidden column

3 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Russell
Top achievements
Rank 1
Russell asked on 22 Nov 2011, 07:47 PM
I have a grid that has a hidden column (the Id) 

 

<telerik:GridBoundColumn DataField="Id" Display="False" Visible="false" 
           FilterControlAltText="Filter column column" UniqueName="column" >
       </telerik:GridBoundColumn>

This works fine for the grid, however when I edit or add a new record (in a popup) the Id shows up.  I can set ReadOnly="true"  which works fine for inserting a new record, this however does not work for editing an existing record.  When ReadOnly is set to true I am unable to get the Id of the record for an update. 

What am I missing here?

Thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Nov 2011, 04:51 AM
Hello,

If you set ReadOnly property of a column as true, then it is not possible to update. Take a look into the Visibility and rendering of columns section in the following documentation for more.
Using Columns

Thanks,
Princy.
0
Russell
Top achievements
Rank 1
answered on 23 Nov 2011, 05:19 PM
I re-read the documentation and I still have noway to hide the column for the "Id" durring an edit or insert. 
0
Antonio Stoilkov
Telerik team
answered on 24 Nov 2011, 04:15 PM
Hi Russell,

I have assembled a sample project demonstrating the desired functionality. The code below demonstrates the main logic. The solution is to change the ReadOnly property depending on the CommandName.
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        GridBoundColumn column = this.RadGrid1.MasterTableView.GetColumn("CategoryID") as GridBoundColumn;
        column.ReadOnly = true;
        RadGrid1.EditIndexes.Clear();
    }
    else if (e.CommandName == RadGrid.EditCommandName)
    {
        GridBoundColumn column = this.RadGrid1.MasterTableView.GetColumn("CategoryID") as GridBoundColumn;
        column.ReadOnly = false;
        RadGrid1.MasterTableView.IsItemInserted = false;
    }
}

Additionally, you could go through the Custom Edit Forms and Different Edit Forms on Edit and Insert sections in the help articles below:

The second topic elaborates on how you can use difference edit forms for edit and insert. Another option is to define your own edit for through the FormTemplate where would you have full control on what controls to display in the different modes.

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Russell
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Russell
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or