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

Hide control in update

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
archimede
Top achievements
Rank 1
archimede asked on 08 Jul 2010, 09:17 AM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Jul 2010, 10:43 AM
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.

Tags
Grid
Asked by
archimede
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or