Progrmatically access form/container to itemEditTemplate

4 posts, 0 answers
  1. Gilberto
    Gilberto avatar
    65 posts
    Member since:
    Sep 2006

    Posted 27 Nov 2009 Link to this post


    Hello,

    I have a RadGrid created at runtime columns , commandItem...everything

    How can i access the form/container to add some control also in runtime?

    I mean , i'd like to add some controls after the buttons update/insert/cancel when i edit/insert a record in grid (  MasterTableView.EditMode = GridEditMode.EditForms;)

    Thanks in advance

    Gilberto
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Nov 2009 Link to this post

    Hello Gilberto,

    Here is the code that I tried to add custom controls to Edit/Insert form. Give a try with following approach.

    CS:
     
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted) 
            { 
                GridEditFormItem editItem = (GridEditFormItem)e.Item; 
                Button btn = new Button(); 
                btn.Text = "Update Form"
                (editItem.FindControl("CancelButton").Parent).Controls.Add(btn); 
            } 
            if (e.Item is GridEditFormInsertItem && RadGrid1.MasterTableView.IsItemInserted ) 
            { 
                GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; 
                Button btn = new Button(); 
                btn.Text = "Insert Form"
                (item.FindControl("CancelButton").Parent).Controls.Add(btn); 
            } 
        } 

    Another suggestion would be using FormTemplate in order to add custom controls to edit/insert form.

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gilberto
    Gilberto avatar
    65 posts
    Member since:
    Sep 2006

    Posted 30 Nov 2009 Link to this post

    Thanks Shinu, its solve part of my desired funcionality. Maybe you can help me with the rest.

    Actually I'd like to insert a RadTabStrip after the insert/cancel button to achieve insert's in OneToOne RelationShip to main grid table.

    Well, with your sugestion i can add a mentioned RadTabStrip, but i actually want to insert this one after the client inserts the record, so, i dont want to exit the edit or insert mode only if the user click the cancel button, any sugestions?

    Resuming, when the grid is in insert or update mode i'd like to exit this mode only if the user click cancel button, but if he clicks insert or update i'd like to insert or update the record without leave the edit or insert mode. Little confusing!!!

    Gilberto
  5. Johny
    Johny avatar
    80 posts
    Member since:
    Aug 2008

    Posted 02 Dec 2009 Link to this post

    Hi Gilberto,

    You can wire the itemCommand event and apply the changes to the database in it. Then you can cancel the command and rebind the grid.This will keep the form open after the database is updated:

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "PerformInsert" || e.CommandName == "Update") 
            { 
                //Update the database here; 
                e.Canceled = true
            } 
            RadGrid1.Rebind(); 
        } 
     

    I hope this helps.
    Johny
Back to Top