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

Stay in insert mode

2 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maarten Alleman
Top achievements
Rank 1
Maarten Alleman asked on 13 Apr 2010, 10:17 AM
How can i stay in insert mode after i created a new record?
i have seen a lot of solutions to close the insert window  but nothing to keep it open.

my code aspx:
<telerik:RadGrid  EnableViewState="true"   EnableEmbeddedSkins="False" Skin="ABCustom" OnItemDataBound="RadGrid2_ItemCommand" 
        runat="server" ID="productrelations"  OnNeedDataSource="datarelations" OnInsertCommand="RadGrid2_InsertCommand" 
        AutoGenerateColumns="false" AllowSorting="true"  > 
        <MasterTableView NoMasterRecordsText="Er zijn momenteel geen vergelijkbare producten geselecteerd" 
            CommandItemDisplay="Top" DataKeyNames="ProductBaseId"
            <Columns> 
                <telerik:GridBoundColumn UniqueName="ProductBaseId" HeaderText="ProductBaseId" DataField="ProductBaseId" 
                    SortExpression="ProductBaseId" Visible="false" ReadOnly="true" /> 
                <telerik:GridTemplateColumn UniqueName="RelatedProducts" AllowFiltering="false" HeaderText="Vergelijkbare producten" 
                    SortExpression="RelatedProductBaseId"
                    <ItemTemplate> 
                        <%# Eval("RelatedProductBase.Name")%> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:DropDownList runat="server" ID="relatedCategory" OnSelectedIndexChanged="fillproduct" 
                            AutoPostBack="true" /> 
                        <asp:DropDownList runat="server" ID="relatedProduct" /> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn AllowFiltering="false"  ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" HeaderText="Acties" UniqueName="Actions"
                    <ItemTemplate> 
                        <asp:ImageButton runat="server" ID="deleterelation" ImageUrl="~/Images/delete.png" 
                            OnCommand="relation_OnClick" CommandArgument='<%# Eval("RelatedProductBaseId") %>' ToolTip="Delete" 
                            OnClientClick="return confirm('Weet u zeker dat u de relatie met dit product wilt verwijderen?');" 
                            CausesValidation="false" /> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
            </Columns> 
            <EditFormSettings EditColumn-ButtonType="ImageButton" EditColumn-InsertImageUrl="~/Images/SaveBtn.gif" 
                EditColumn-UpdateImageUrl="~/Images/SaveBtn.gif" EditColumn-CancelImageUrl="~/Images/CancelBtn.gif"
            </EditFormSettings> 
            <CommandItemSettings AddNewRecordText="Vergelijkbare producten toevoegen" AddNewRecordImageUrl="~/Images/AddRecord.gif" 
                RefreshText="Verversen" RefreshImageUrl="~/Images/Refresh.gif" /> 
        </MasterTableView> 
    </telerik:RadGrid> 

aspx.cs:
        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if ((e.Item is GridEditFormItem) && e.Item.IsInEditMode) 
            { 
                PrefetchPath prefetch = new PrefetchPath(EntityType.CategoryBaseEntity); 
                prefetch.Add(CategoryBaseEntity.PrefetchPathSubCategoryBase); 
                GridEditFormItem categorydopdown = (GridEditFormItem)e.Item; 
                DropDownList dropdownlistcategory = (DropDownList)categorydopdown.FindControl("relatedCategory"); 
 
                CategoryBaseCollection theCategoryColl = new CategoryBaseCollection(); 
                theCategoryColl.GetMulti(CategoryBaseFields.IsActive == true, prefetch); 
                dropdownlistcategory.Items.Add(new ListItem("- Selecteer een Category -""0")); 
                foreach (CategoryBaseEntity category in theCategoryColl) 
                { 
                    dropdownlistcategory.Items.Add(new ListItem(category.Name, category.Id.ToString())); 
                    foreach (SubCategoryBaseEntity subCategory in category.SubCategoryBase) 
                    { 
                        dropdownlistcategory.Items.Add(new ListItem(".." + subCategory.Name, ".." + subCategory.Id.ToString())); 
                    } 
                } 
            } 
        } 
 
        protected void RadGrid2_InsertCommand(object source, GridCommandEventArgs e) 
        { 
            GridEditFormInsertItem insertitems = (GridEditFormInsertItem)e.Item; 
             
            ProductRelationBaseEntity newproduct = new ProductRelationBaseEntity(); 
             
            DropDownList deliverytime = (DropDownList)insertitems.FindControl("relatedProduct"); 
            newproduct.ProductBaseId = Url.QueryStringParser.GetInt("ProductId"); 
            newproduct.RelatedProductBaseId = int.Parse(deliverytime.SelectedValue); 
            newproduct.Save(); 
            productrelations.DataBind(); 
             
             
             
 
             
        } 
 
 
        protected void fillproduct(object sender, EventArgs e) 
        { 
 
            DropDownList dropdownlistcategory = (DropDownList)sender; 
            DropDownList dropdownlistprodudct = (DropDownList)dropdownlistcategory.Parent.FindControl("relatedProduct"); 
            ProductBaseCollection productcollection = new ProductBaseCollection(); 
 
 
            if (dropdownlistcategory.SelectedItem.Text.Substring(0, 2) == ".."
            { 
                productcollection.GetMulti(ProductBaseFields.SubCategoryBaseId == int.Parse(dropdownlistcategory.SelectedValue.Substring(2, dropdownlistcategory.SelectedValue.Length - 2)) & ProductBaseFields.IsDeleted == false); 
            } 
            else 
            { 
                productcollection.GetMulti(ProductBaseFields.CategoryId == int.Parse(dropdownlistcategory.SelectedValue) & ProductBaseFields.IsDeleted == false); 
            } 
 
            dropdownlistprodudct.Items.Clear(); 
            dropdownlistprodudct.Items.Add(new ListItem("- Selecteer een product -""0")); 
            foreach (ProductBaseEntity product in productcollection) 
            { 
                ProductRelationBaseEntity productrelation = new ProductRelationBaseEntity(Url.QueryStringParser.GetInt("ProductId"), product.Id); 
                if (productrelation.IsNew == true && Url.QueryStringParser.GetInt("ProductId") != product.Id) 
                    dropdownlistprodudct.Items.Add(new ListItem(product.Name, product.Id.ToString())); 
            } 
        } 
 
    protected void datarelations(object source, GridNeedDataSourceEventArgs e) 
        { 
            ProductRelationBaseCollection product = new ProductRelationBaseCollection(); 
            product.GetMulti(ProductRelationBaseFields.ProductBaseId == Url.QueryStringParser.GetInt("ProductId")); 
            productrelations.DataSource = product; 
        } 


2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Apr 2010, 12:04 PM
Hello,

Try out the following code snippet in order to show insert form after creating each record.

C#:
 
    bool insert = false
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    { 
        insert = true
    } 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (insert) 
        { 
            RadGrid1.MasterTableView.IsItemInserted = true
            RadGrid1.MasterTableView.Rebind(); 
        } 
    } 

-Shinu.
0
Maarten Alleman
Top achievements
Rank 1
answered on 13 Apr 2010, 01:39 PM
worked like a charm, thanks a lot.
Tags
Grid
Asked by
Maarten Alleman
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Maarten Alleman
Top achievements
Rank 1
Share this question
or