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

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

1 Answer 15 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yoong
Top achievements
Rank 1
Yoong asked on 04 Sep 2013, 08:29 PM
Hello,
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>">
      <ItemTemplate>
          <%#DataBinder.Eval(Container.DataItem, "WellnessFactor")%>
      </ItemTemplate>
      <EditItemTemplate>
          <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">
              <Items>
                  <telerik:RadComboBoxItem Text="Yes" Value="Yes" />
                  <telerik:RadComboBoxItem Text="No" Value="No" />
              </Items>
          </telerik:RadComboBox>
          <asp:RequiredFieldValidator ID="ValidateWellnessFactorComboBox" runat="server" ControlToValidate="WellnessFactorComboBox"
              ValidationGroup="SubscriberGroup" ErrorMessage="*This field is required" ForeColor="Red"
              InitialValue="">
          </asp:RequiredFieldValidator>
      </EditItemTemplate>
  </telerik:GridTemplateColumn>

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;
                    break;
                }
            }
        }
    }
}

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.

-Yoong

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 09 Sep 2013, 08:37 AM
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.

C#:
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
    }
}

Thanks,
Shinu.


Tags
General Discussions
Asked by
Yoong
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or