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

Progrmatically access form/container to itemEditTemplate

3 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gilberto
Top achievements
Rank 1
Gilberto asked on 27 Nov 2009, 01:43 PM

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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Nov 2009, 06:38 AM
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.
0
Gilberto
Top achievements
Rank 1
answered on 30 Nov 2009, 05:52 PM
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
0
Johny
Top achievements
Rank 1
answered on 02 Dec 2009, 02:36 PM
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
Tags
Grid
Asked by
Gilberto
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gilberto
Top achievements
Rank 1
Johny
Top achievements
Rank 1
Share this question
or