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

How to hide an invisible column in EditForm or PopUp

6 Answers 558 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Orlando
Top achievements
Rank 1
Orlando asked on 15 Sep 2010, 06:03 PM
I have a column with Visible=False. It doesn't show in InPlace edit more, but will show in EditForm and PopUp edit mode. How can I hide it in all edit modes?

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Sep 2010, 03:58 AM
Hello Orlando,

In order to hide a column in EditForm/PopUp edit mode, set the column's ReadOnly propert as true.

ASPX:
<telerik:GridBoundColumn DataField="FirstName" ReadOnly="true" Visible="false" HeaderText="FirstName" UniqueName="FirstName">
</telerik:GridBoundColumn>

Thanks,
Princy.
0
Orlando
Top achievements
Rank 1
answered on 20 Sep 2010, 05:58 AM
I understand to set readonly = true will make it 'hidden' in popup forms.

but, the situation is that the hidden field is actually a foreign key fields that gets filled in ItemCommand (see code below), when it's set to visible=false, it works well in InPlace Edit mode, but when it's set to visible=false, ReadOnly=true, and use Popup mode, to save a new record will generate key error, it looks like the value has not been assigned.  How shall I handle this?

* HotelID is the foreign key of the RadGrid table, it shall be hidden in all edit mode, and is assigned in the following code.
 
  protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {          
            if (e.CommandName == RadGrid.InitInsertCommandName)
            {
             
                e.Canceled = true;            
                newValues["HotelID"] = Session["HotelID"];
                //Insert the item and rebind
                e.Item.OwnerTableView.InsertItem(newValues);
            }
  }
0
Princy
Top achievements
Rank 2
answered on 20 Sep 2010, 10:29 AM
Hello Orlando,

 Give a try with hiding the control only in edit mode, instead of setting the ReadOnly property.

C#:
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
   {
        if ((e.Item is GridEditFormItem && e.Item.IsInEditMode) && !(e.Item is GridEditFormInsertItem)) // hide the control in edit mode
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           TextBox txt = (TextBox)editItem["HotelID"].Controls[0];
           txt.Parent.Parent.Visible = false;
       }
  }

Thanks,
Princy.

0
Orlando
Top achievements
Rank 1
answered on 20 Sep 2010, 05:33 PM
This works great!

But why do I need,

 && !(e.Item is GridEditFormInsertItem)?
0
Princy
Top achievements
Rank 2
answered on 21 Sep 2010, 05:33 AM
Hello Orlando,

The above code is for hiding the control only in edit mode. So the conidtion (! e.Item is GridEditFormInsertItem) is for not executing that code when the grid is in insert mode.

Thanks,
Princy.
0
Chillax
Top achievements
Rank 1
answered on 20 Jul 2012, 10:12 AM
Tags
Grid
Asked by
Orlando
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Orlando
Top achievements
Rank 1
Chillax
Top achievements
Rank 1
Share this question
or