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

Hide Labels in Add Form

2 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 15 Aug 2013, 04:53 PM
I have three columns (EventID, EventName, DateCreated) in a RadGrid which I've attached some Manual CRUD operations to. EventID and DateCreated are created automatically in SQL and never need to be updated, so I have hidden their text boxes in the Add Form and disabled them in the Edit Form. My problem is: in the Add Form, their labels stay visible.

How can I hide those labels? I have attached a picture, and code for hiding/disabling text boxes are below.

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
                GridEditableItem item = e.Item as GridEditableItem;
                GridEditManager manager = item.EditManager;
                GridTextBoxColumnEditor editor = manager.GetColumnEditor("EventID") as GridTextBoxColumnEditor;
                GridTextBoxColumnEditor editor2 = manager.GetColumnEditor("DateCreated") as GridTextBoxColumnEditor;
            if (!(e.Item is GridEditFormInsertItem)) //edit record
            {
                editor.TextBoxControl.Enabled = false;
                editor2.TextBoxControl.Enabled = false;
            }
            else //add record
            {
                editor.TextBoxControl.Visible = false;
                editor2.TextBoxControl.Visible = false;
            }
        }
    }

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 16 Aug 2013, 03:47 AM
Hi Matthew,

To hide a column in insert mode,please try the below code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
  {
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
      {
          GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item;
          insertitem["UniqueName"].Parent.Visible = false;
      }
  }

Thanks,
Princy
0
Matthew
Top achievements
Rank 1
answered on 16 Aug 2013, 02:31 PM
It works!

Thanks Princy
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Share this question
or