
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

Suggestions please??
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.

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.

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.


GridEditFormItem editedFormItem = (GridEditFormItem)this.Parent.NamingContainer;
string a = editFormitem["WhatEver"].Text;

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?