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

Unable to find ChildItem of the parent grid

2 Answers 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MadhuSudhan
Top achievements
Rank 1
MadhuSudhan asked on 22 Apr 2011, 07:36 AM
Hi, I am facing a issue to find the ChildItem of the parent grid in ItemCreated event of Child grid after doing paging or filtering or sorting on parent grid.
Here is my code of OnNeedDataSource for Parent Grid :
public void GetInProcessData(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    EffortCertificationList effortCertifications = new EffortCertificationList();
    if (Session["IPEffortCertifications"] != null)
    {   effortCertifications = (EffortCertificationList)Session["IPEffortCertifications"];  }
    else
    {   effortCertifications.CurrEmployee = Session["currEmployee"].ToString();
        effortCertifications.Load("InProcess");
        Session["IPEffortCertifications"] = effortCertifications;
    }
   grdInProcess.DataSource = effortCertifications;
}

Here is my code of OnNeedDataSource for Child Grid which is in NestedViewTemplate :
protected void GetInProcesDetails(object source, GridNeedDataSourceEventArgs e)
{
                GridDataItem parentItem = ((source as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
                string _employeeId = parentItem.GetDataKeyValue("Employee").ToString();
                Label lblBeginDate = (Label)parentItem.FindControl("lblIPStartDate");
                Label lblEndDate = (Label)parentItem.FindControl("lblIPEndDate");
                EffortCertificationList objeffortCertifications = new EffortCertificationList();
               if (Session["IPEffortCertifications"] != null)
               {
               objeffortCertifications = (EffortCertificationList)Session["IPEffortCertifications"];
               var effortDetails = from ec in objeffortCertifications
                                            where ec.Employee == _employeeId && ec.CertPeriodStartDate ==                                          Convert.ToDateTime(lblBeginDate.Text) && ec.CertPeriodEndDate == Convert.ToDateTime(lblEndDate.Text)
                                            select ec;
               EffortDetailList objEffortDetails = new EffortDetailList();
               foreach (var ed in effortDetails)
               {
                       objEffortDetails = ed.Details;
               }
               (source as RadGrid).AllowFilteringByColumn = false;
               (source as RadGrid).DataSource = objEffortDetails;
    }
 protected void grdInProcesDetails_ItemCreated(object sender, GridItemEventArgs e)
 {
       if (e.Item is GridDataItem)
       {
                GridDataItem item = (GridDataItem)e.Item;
                GridDataItem parentItem = ((sender as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
                if (parentItem != null && parentItem.ChildItem !=null)
                {   string _employeeId = parentItem.GetDataKeyValue("Employee").ToString();
                    CheckBox chkIPReviewed = parentItem.ChildItem.FindControl("chkInProcessReviewed") as CheckBox;
                }
     }
}

Here in this event parentItem.ChildItem is null because of which i could not add attribute for calling javascript funcation for chkIPReviewed control. This is happening only after paging or sorting or filtering.
I am using client side function to expand or collapse for showing the Inner grid which is present in Nesstedviewtemplate.

Please provide me a solution.

Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 27 Apr 2011, 06:31 PM
Hello MadhuSudhan,

The approach you are using is correct but you have to make sure that the ParentItem is initialized in order to access it. The ItemCreated event might be called to early and the parent grid item might not be bound yet. Try using the ItemDataBound or some other later event (e.g. PagePreRender) where you are sure that the items are created and bound properly.

Kind regards,
Marin
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
MadhuSudhan
Top achievements
Rank 1
answered on 28 Apr 2011, 06:21 AM
Thank you very much for the reply..I was already able to solve the issue. Yes i tried using with Item_DataBound event but it was not successful, However when used Inner grid pre_render event i got my requirements fulfill.

Thank you once again for your response...
Tags
Grid
Asked by
MadhuSudhan
Top achievements
Rank 1
Answers by
Marin
Telerik team
MadhuSudhan
Top achievements
Rank 1
Share this question
or