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

Access EditForm in Grid from ObjectDatasource Inserting Event

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farhan
Top achievements
Rank 1
Farhan asked on 31 Aug 2011, 02:34 PM
 Hi, I am using entity framework, ObjectDataSource and an object class to bind RadGrid. I want to access some of the controls in the edit form from the Object Data souce inserting event but need some help with this. I know i have to access  GridEditFormInsertItem somehow to access the control but I dont know how to reach it from the object Data source inserting event. So far all the examples I have seen are like

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
       
           if ((e.CommandName == RadGrid.PerformInsertCommandName)) 
           
               //the dropdown list will be the first control in the Controls collection of the corresponding cell   
               DropDownList list = (e.Item as GridEditableItem)["ddlContactName"].Controls[0] as DropDownList; 
           
       }


This is really what I want to do...but from the ObjectDataSource Inserting event since I need to add an insert parameter for the object class my objectDatasource is tied to....I have tried to access the GridCommandEventArgs or the GridEditFormInsertItem like below but no luck so far... can someone please show me how to do this?

protected void ObjectDataSource1_Inserting(object sender, System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e) 
        
                
            ((DAL.DTO.DataTypeObject)e.InputParameters[0]).product.product_id = (int)Session["CustomerID"]; 
       
             //These dont work...how can I access my Edit form or GridCommandEventArgs from this event in objectDatasource      
             //inserting event to access my dropdownlist?? 
            //Telerik.Web.UI.GridEditFormInsertItem myInsertForm = ((Telerik.Web.UI.GridEditFormInsertItem)RadGrid1.FindControl("EditFormControl")); 
    
            //Telerik.Web.UI.GridEditFormInsertItem myInsertForm = ((Telerik.Web.UI.GridEditFormInsertItem)RadGrid1.EditItems[0]);

                       }

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 01 Sep 2011, 12:59 PM
Hello Farhan,

In order to achieve the required functionality you could use the  GetInsertItem() server method of the RadGrid MasterTableView. For example:
protected void ObjectDataSource1_Inserting(object sender, System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e) 
 
        
           RadGrid1.MasterTableView.GetInsertItem().FindControl("EditFormControl");
        }


I hope this helps.

Best wishes,
Maria Ilieva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Farhan
Top achievements
Rank 1
answered on 01 Sep 2011, 02:11 PM
Yup thanks Maria, I found out that works, hope it helps someone else as well.
Tags
Grid
Asked by
Farhan
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Farhan
Top achievements
Rank 1
Share this question
or