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

Unable to get the user Control

8 Answers 231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FireHolster
Top achievements
Rank 1
FireHolster asked on 03 Aug 2011, 09:37 PM

 

 

I am trying to get the user control on th eItemcommand of the grid but it is coming null. can some one please help as in what i am missing in here.

the user control comes null. please help.......
Code Behind

protected
void GridResult_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

 

if (e.CommandName == RadGrid.EditCommandName)

 

{

 

 

GridDataItem item = e.Item as GridDataItem;

 

 

 

UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

 

(userControl.FindControl(

 

"A") as HiddenField).Value = item["x"].Text;

 

(userControl.FindControl(

 

"B") as HiddenField).Value = item["Y"].Text;

 

}

}

Page Details.
Grid Columns:
this is my button

 

 

<telerik:GridEditCommandColumn UniqueName="actionsCommandColumn" EditText="Go" ButtonType="PushButton">

 

 

 

</telerik:GridEditCommandColumn>

<

 

 

EditFormSettings PopUpSettings-Modal="true" InsertCaption="Actions" UserControlName="CustomControl.ascx"

 

 

 

 

 

 

 

EditFormType="WebUserControl">

 

</EditFormSettings>

 

 

 

 

8 Answers, 1 is accepted

Sort by
0
FireHolster
Top achievements
Rank 1
answered on 03 Aug 2011, 11:29 PM

Suggestions please??
0
Andrey
Telerik team
answered on 04 Aug 2011, 04:15 PM
Hello Bikrant,

When Edit command is fired, the edit form is not created yet. Therefore, the Null value is assigned to the UserControl. The proper place to access the edit form controls is ItemDataBound. Please examine the sample code snippet below and let me know if it works as expected:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item.IsInEditMode)
           {
               GridEditFormItem editFormItem = e.Item as GridEditFormItem;
               UserControl userControl= (UserControl)editFormItem.FindControl(GridEditFormItem.EditFormUserControlID);
               (userControl.FindControl("A") as HiddenField).Value = item["x"].Text;
               (userControl.FindControl("B") as HiddenField).Value = item["Y"].Text;
           }
       }

All the best,
Andrey
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
FireHolster
Top achievements
Rank 1
answered on 04 Aug 2011, 09:37 PM
I tried this on the itemdatabound but it is still returning me null for the user control :(
0
Andrey
Telerik team
answered on 05 Aug 2011, 12:48 PM
Hello Bikrant,

I have made a sample project for you. Please give it a try and let me know if it works on your end.

Regards,
Andrey
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
FireHolster
Top achievements
Rank 1
answered on 15 Aug 2011, 05:47 PM
well the itemdatabound is now working and i figured out why it was not working for me.

I was expecting that the user control will load after the Itemdatabound event is triggered on the grid. but that is not the case. The Page_Load of the control happens before the grids item data bound. i want the control fields to get set when they are accessed in the Page_Load of the user control.

0
FireHolster
Top achievements
Rank 1
answered on 15 Aug 2011, 06:10 PM
when i say itemdatabound is triggered after, i mean that the item comes in edit mode only after the user control page_load is complete.
0
FireHolster
Top achievements
Rank 1
answered on 15 Aug 2011, 09:54 PM
here's what all i have to do on the page load of the User control (editform) to get the grid item and set the controls

 

 

GridEditFormItem editedFormItem = (GridEditFormItem)this.Parent.NamingContainer;

 


string a = editFormitem["WhatEver"].Text;

0
Pravesh
Top achievements
Rank 1
answered on 14 Oct 2011, 04:06 PM
Hi Bikrant,

I tried your solution below:
"here's what all i have to do on the page load of the User control (editform) to get the grid item and set the controls

 

 

GridEditFormItem editedFormItem = (GridEditFormItem)this.Parent.NamingContainer;

 


string a = editFormitem["WhatEver"].Text;"

This did not work, I got the following error: "Unable to cast object of type 'Microsoft.SharePoint.WebPartPages.SPWebPartManager' to type 'Telerik.Web.UI.GridEditFormItem'."

Please help?
Tags
Grid
Asked by
FireHolster
Top achievements
Rank 1
Answers by
FireHolster
Top achievements
Rank 1
Andrey
Telerik team
Pravesh
Top achievements
Rank 1
Share this question
or