Edit/Insert on Item

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

    Posted 05 Jul 2010 Link to this post

    I have a RadGrid (I post the ASPX code below) and I want a different behavior in Edit/insert: when I enter in Edit mode I want AziendaRadCombobox to be disabled. Instead when I enter in Insert mode I want it Enabled. EditItemTemplate seems not to distinguish between edit and insert. Is there a simple way? Can you provide me a solution?

    Thanks.

    <telerik:RadGrid ID="RadGridAziendeForUser" runat="server" DataSourceID="ObjectDataSourceAziendeUtente" 
                    EnableEmbeddedSkins="False" GridLines="None" Skin="MachinaWeb" AllowAutomaticUpdates="True" 
                    AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowMultiRowSelection="True" 
                    OnItemCommand="RadGridAziendeForUser_ItemCommand" OnItemDataBound="RadGridAziendeForUser_ItemDataBound" 
                    AllowPaging="True" PageSize="5">  
                    <ClientSettings EnablePostBackOnRowClick="True">  
                        <Selecting AllowRowSelect="True" /> 
                        <Scrolling EnableVirtualScrollPaging="True" ScrollHeight="200px" /> 
                    </ClientSettings> 
                    <MasterTableView AutoGenerateColumns="False" DataSourceID="ObjectDataSourceAziendeUtente" 
                        EditMode="InPlace" CommandItemDisplay="Top" DataKeyNames="IdUtente,IdAzienda" 
                        > 
                        <CommandItemTemplate> 
                            <div style="float: left;">  
                                <asp:LinkButton Text="Nuova Azienda" ID="Insert" runat="server" CommandName="InitInsert" /> 
                            </div> 
                        </CommandItemTemplate> 
                        <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">  
                                <ItemStyle Width="40px" /> 
                            </telerik:GridEditCommandColumn> 
                            <telerik:GridBoundColumn DataField="IdUtente" DataType="System.Int64" HeaderText="IdUtente" 
                                ReadOnly="True" SortExpression="IdUtente" UniqueName="IdUtente" Visible="false">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="IdUtenteAsp" HeaderText="IdUtenteAsp" SortExpression="IdUtenteAsp" 
                                UniqueName="IdUtenteAsp" DataType="System.Guid" Visible="false">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="UserName" HeaderText="UserName" ReadOnly="True" 
                                SortExpression="UserName" UniqueName="UserName" Visible="false">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura" 
                                ReadOnly="True" SortExpression="IdCultura" UniqueName="IdCultura" Visible="false">  
                            </telerik:GridBoundColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label46" runat="server" Text="Azienda" Width="130px"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="AziendaRadComboBox" runat="server" DataSourceID="ObjectDataSourceAzienda" 
                                        DataTextField="NomeAzienda" DataValueField="IdAzienda" SelectedValue='<%# Bind("IdAzienda") %>' 
                                        Width="120px" Enabled="false" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label47" runat="server" Width="120px" Text='<%# Bind("Azienda") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label48" runat="server" Text="Cultura" Width="80px"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="CulturaRadComboBox" runat="server" DataSourceID="ObjectDataSourceCultura" 
                                        DataTextField="Cultura" DataValueField="IdCultura" SelectedValue='<%# Bind("IdCultura") %>' 
                                        Width="70px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label50" runat="server" Width="70px" Text='<%# Bind("Cultura") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label49" runat="server" Text="Gruppo" Width="130px"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="GruppoRadComboBox" runat="server" DataSourceID="ObjectDataSourceGruppoUtente" 
                                        DataTextField="Nome" DataValueField="IdGruppoUtente" SelectedValue='<%# Bind("IdGruppo") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label51" runat="server" Text='<%# Bind("Gruppo") %>' Width="120px"></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label52" runat="server" Text="Stabilimento" Width="130px"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="StabilimentoRadComboBox" runat="server" DataSourceID="ObjectDataSourceStabilimento" 
                                        DataTextField="Denominazione" DataValueField="IdStabilimento" SelectedValue='<%# Bind("IdStabilimento") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label53" runat="server" Text='<%# Bind("Stabilimento") %>' Width="120px"></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label54" runat="server" Text="Reparto" Width="130px"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="RepartoRadComboBox" runat="server" DataSourceID="ObjectDataSourceReparto" 
                                        DataTextField="Reparto" DataValueField="IdReparto" SelectedValue='<%# Bind("IdReparto") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label55" runat="server" Text='<%# Bind("Settore") %>' Width="120px"></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridButtonColumn CommandName="Delete" ImageUrl="~/Images/ImagesGrid/Delete.gif" 
                                UniqueName="DeleteColumn" ConfirmText="Do you really want to delete the selected row?" 
                                ButtonType="ImageButton" /> 
                        </Columns> 
                        <EditFormSettings> 
                            <EditColumn> 
                            </EditColumn> 
                        </EditFormSettings> 
                    </MasterTableView> 
                    <FilterMenu EnableEmbeddedSkins="False">  
                    </FilterMenu> 
                    <HeaderContextMenu EnableEmbeddedSkins="False">  
                    </HeaderContextMenu> 
                </telerik:RadGrid> 
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jul 2010 Link to this post

    Hello,


    Access the RadComboBox control in ItemCreated/ItemDataBound handler and set the Enabled property accordingly after check whether the grid in editmode or in insertmode.

    The online documentation shows how to distinguish between edit and insert mode:
    Distinguish edit/insert mode on ItemCreated/ItemDataBound


    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 05 Jul 2010 Link to this post

    Only one thing.

    I've to enable/disable a control, so I set the dropdown as enabled=false and in the DataBound event I do the first part of the "if"

            if (e.Item.OwnerTableView.IsItemInserted)  
            {  
                //item is about to be inserted  
                if (e.Item is GridDataInsertItem)  
                {  
                    ((RadComboBox)e.Item.FindControl("AziendaRadComboBox")).Enabled = true;  
                }  
            }  
            else 
            {  
                //item is about to be edited  
                if (e.Item is ...)  
                {  
                    ((RadComboBox)e.Item.FindControl("AziendaRadComboBox")).Enabled = false;  
                }  
            } 

    I'd like also to put the second to be sure that in Edit it'll be disabled. The problem is that in Insert I find GridDataInsertItem but in edit what should I use?
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2010 Link to this post

    Hello ,

    You can use the following condition to disable the RadComboBox in edit mode.

    C#:
      
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item.OwnerTableView.IsItemInserted) 
            { 
                //item is about to be inserted   
                if (e.Item is GridDataInsertItem) 
                { 
                    ((RadComboBox)e.Item.FindControl("AziendaRadComboBox")).Enabled = true
                } 
            } 
            if (!(e.Item is GridDataInsertItem) && e.Item.IsInEditMode) 
                //item is about to be edit 
            { 
                ((RadComboBox)e.Item.FindControl("AziendaRadComboBox")).Enabled = false
            }   
        } 

    Thanks,
    Princy.

Back to Top