Unable to prevent GrodTemplateColumn from appearing in Edit Form when Adding or Editing

2 posts, 0 answers
  1. Yoong
    Yoong avatar
    6 posts
    Member since:
    Aug 2013

    Posted 04 Sep 2013 Link to this post

    I currently have a hierarchical grid where I need to selectively hide certain columns and prevent it from appearing in Add/Edit form. I am able to selectively hide the column but was not able to prevent it from appearing in the Edit Form when user click on Add or Edit

    Here is the snippet of one of columns that I need to hide programatically. Note that I am not using GrodBoundColumn and most of my columns are using GridTemplateColumn with ItemTemplate and EditItemTemplate as shown below
    <telerik:GridTemplateColumn UniqueName="WellnessFactor" HeaderText="Wellness Factor<span style='color:#CD4800'>*</span>">
              <%#DataBinder.Eval(Container.DataItem, "WellnessFactor")%>
              <telerik:RadComboBox ID="WellnessFactorComboBox" runat="server" AllowCustomText="false"
                  AutoPostBack="false" CausesValidation="false" DataTextField="WellnessFactor"
                  DataValueField="WellnessFactor" EmptyMessage="Please Select..." EnableVirtualScrolling="true"
                  Height="45px" MarkFirstMatch="true" NoWrap="True" Skin="WebBlue" Width="150px">
                      <telerik:RadComboBoxItem Text="Yes" Value="Yes" />
                      <telerik:RadComboBoxItem Text="No" Value="No" />
              <asp:RequiredFieldValidator ID="ValidateWellnessFactorComboBox" runat="server" ControlToValidate="WellnessFactorComboBox"
                  ValidationGroup="SubscriberGroup" ErrorMessage="*This field is required" ForeColor="Red"

    Here is the snippet of code use to hide the column

    protected void RadGrid1_OnPreRender(object sender, EventArgs e)
        if (listHideColumn.Count > 0)
            foreach (GridColumn column in RadGrid1.Columns)
                foreach (string columnName in listHideColumn)
                    if (column.UniqueName == columnName)
                        column.Visible = false;
                        //(column as GridBoundColumn).Visible = false;

    Most of the solution I found online is to make the column readonly. But I am not using GridBoundColumn. Is there a way to prevent it from appearing it in Edit Form when user click on Add or Edit since they are not visible on the Grid. Note that I am using auto generating form.

    Your help in resolving this will be greatly appreciated.

    Thank you.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Sep 2013 Link to this post

    Hi Yoong,

    I guess you have to prevent a GridTemplateColumn from appearing in edit/insert mode. Please try accessing the control in EditItemTemplate in ItemDataBound event and set the visible property as shown below.

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            GridEditableItem EditItem = (GridEditableItem)e.Item;
            RadComboBox comboBox = (RadComboBox)EditItem.FindControl("WellnessFactorComboBox"); //accessing the RadComboBox in EditItemTemplate
            comboBox.Visible = false; //setting the visibility


Back to Top