Hide control in update

2 posts, 1 answers
  1. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 08 Jul 2010 Link to this post

    In grid edit panel I want to show/hide some control inside 2 "templatecolumn" and a checkbox  "checkboxcolumn":

    <telerik:RadGrid ID="RadGridParametriConfigurazione" runat="server" EnableEmbeddedSkins="False"
                    GridLines="None" Skin="MachinaWeb" AllowPaging="true" PageSize="15" AllowAutomaticUpdates="true"
                    EnableAjaxSkinRendering="False" OnItemCommand="RadGridParametriConfigurazione_ItemCommand">
                    <MasterTableView AutoGenerateColumns="False">
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/ImagesGrid/Cancel.gif"
                                EditImageUrl="~/Images/ImagesGrid/Edit.gif" UpdateImageUrl="~/Images/ImagesGrid/Update.gif"
                                InsertImageUrl="~/Images/ImagesGrid/Update.gif" UniqueName="EditCommandColumn"
                                ItemStyle-Width="40px" />
                            <telerik:GridBoundColumn DataField="IdParametro" DataType="System.Int64" HeaderText="IdParametro"
                                SortExpression="IdParametro" UniqueName="IdParametro" ReadOnly="true" Visible="false">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura"
                                SortExpression="IdCultura" UniqueName="IdCultura" ReadOnly="true" Visible="false">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="DescrizioneParametro" HeaderText="DescrizioneParametro"
                                SortExpression="DescrizioneParametro" UniqueName="DescrizioneParametro" ReadOnly="true">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn HeaderText="Descrizione" UniqueName="TemplateColumnDescrizione">
                                <HeaderTemplate>
                                    <asp:Label ID="LabelDescrizione" runat="server" Text="Descrizione"></asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="LabelDescrizione" runat="server" Text='<%# Bind("DescrizioneTextBox") %>' Width="250px"></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBoxDescrizione" runat="server" Text='<%# Bind("DescrizioneTextBox") %>' Width="250px"></asp:TextBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="TemplateColumnValore" HeaderText="ValoreComboBox">
                                <HeaderTemplate>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="LabelComboBoxValore" runat="server" Text='<%# Bind("ValoreComboBox") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="RadComboBoxValore" runat="server" Width="250px">
                                    </telerik:RadComboBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridCheckBoxColumn DataField="Abilitato" HeaderText="Abilitato" SortExpression="Abilitato"
                                UniqueName="Abilitato">
                            </telerik:GridCheckBoxColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn>
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                </telerik:RadGrid>

    I tryed in ItemCommand with this code without success:

    protected void RadGridParametriConfigurazione_ItemCommand(object source, GridCommandEventArgs e)
       {
           switch (e.CommandName)
           {
               case "Edit":
                   GridEditableItem editedItem = (GridEditableItem)(e.Item);
                   GridEditManager editMan = editedItem.EditManager;
                   GridTemplateColumnEditor templateColumnValoreEditor = (GridTemplateColumnEditor)(editMan.GetColumnEditor("TemplateColumnValore"));
                   GridTemplateColumnEditor templateColumnDescrizioneEditor = (GridTemplateColumnEditor)(editMan.GetColumnEditor("TemplateColumnDescrizione"));
                   GridCheckBoxColumnEditor checkBoxColumnEditor = (GridCheckBoxColumnEditor)(editMan.GetColumnEditor("Abilitato"));
                   checkBoxColumnEditor.ContainerControl.Controls[0].Visible = false;
                   //templateColumnValoreEditor.ContainerControl.FindControl("RadComboBoxValore").Visible = false;
                   break;
           }
       }

    It seems I can only access fields in Item and not in EditTemplate. Why? How can I hide a control in edit?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Jul 2010 Link to this post

    Hello Archimede,

    Try the following code in ItemDataBound event to hide the control in edit mode.

    C#:
    protected void RadGridParametriConfigurazione_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
           {
               GridEditFormItem editedItem = (GridEditFormItem)e.Item;
               CheckBox chk = (CheckBox)editedItem["Abilitato"].Controls[0];
               chk.Parent.Parent.Visible = false;
           }
       }

    Thanks,
    Princy.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top