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

[Solved] Nested RadGrid's MasterTableView disappears

4 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 17 Jul 2013, 08:57 PM
I've run into this issue before, but I can't remember how I resolved (or avoided) it.

I've nested a RadGrid inside the NestedViewTemplate of another RadGrid. I've attached a picture of the issue. In this case I expanded the first row (at which point things look normal) and then the second row. In Firebug I've selected the nested RadGrid of the first row which appears to be a solid line. It seems the MasterTableView has disappeared. The outer grid is ajaxified, but the behavior is identical when I set EnableAjax="false". I'll paste the code for the RadGrids. The outer grid is rgAgencies; the inner grid is rgSpecifications; rg refers to both grids (and so rgMaster refers to both grids' MasterTableView).

protected void rgMaster_Init(object sender, EventArgs e)
{
    GridTableView gtv = sender as GridTableView;
    gtv.CommandItemDisplay = UserInfo.IsInRole(PortalSettings.AdministratorRoleName) ? GridCommandItemDisplay.Top : GridCommandItemDisplay.None;
}
 
protected void rgAgencies_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    using (EXSCInternshipsDataContext dbContext = new EXSCInternshipsDataContext())
    {
        rgAgencies.DataSource = dbContext.Agencies.Where(a => !a.AgencyDeleted).ToList();
    }
}
 
protected void rgSpecifications_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid rg = sender as RadGrid;
    GridDataItem item = ((GridNestedViewItem)rg.NamingContainer).ParentItem as GridDataItem;
    using (EXSCInternshipsDataContext dbContext = new EXSCInternshipsDataContext())
    {
        Agency agency = dbContext.Agencies.Single(a => a.AgencyID == Convert.ToInt32(item.GetDataKeyValue("AgencyID")));
        IEnumerable<InternshipSpecification> list = agency.InternshipSpecifications.ToList();
        if (list.Count() == 0) rg.Visible = UserInfo.IsInRole(PortalSettings.AdministratorRoleName);
        else rg.DataSource = agency.InternshipSpecifications.ToList();
    }
}
 
protected void rgAgencies_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        using (EXSCInternshipsDataContext dbContext = new EXSCInternshipsDataContext())
        {
            Agency agency = dbContext.Agencies.Single(a => a.AgencyID == Convert.ToInt32(item.GetDataKeyValue("AgencyID")));
            RadRating rr = item["Rating"].Controls.OfType<RadRating>().Single();
            IEnumerable<Score> ratings = agency.AForms.Select(a => a.Internship).
                                                        Where(i => i.InternshipGFormID.HasValue && i.GForm.OverallScore.ScoreValue != Score.NA).
                                                        Select(i => i.GForm.OverallScore).ToList();
            if (ratings.Count() == 0) rr.Enabled = false;
            else rr.Value = ratings.Select(s => s.ScoreValue - 1).Average(i => (decimal)i);
        }
    }
}
 
protected void rgAgencies_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "InitInsert")
    {
        e.Canceled = true;
        rwEditAgency.VisibleOnPageLoad = true;
        loadAgencyData(null);
    }
    else if (e.CommandName == "Edit")
    {
        e.Canceled = true;
        rwEditAgency.VisibleOnPageLoad = true;
        using (EXSCInternshipsDataContext dbContext = new EXSCInternshipsDataContext())
        {
            Agency agency = dbContext.Agencies.Single(a => a.AgencyID == Convert.ToInt32((e.Item as GridEditableItem).GetDataKeyValue("AgencyID")));
            loadAgencyData(agency);
        }
    }
    else if (e.CommandName == "Delete")
    {
        using (EXSCInternshipsDataContext dbContext = new EXSCInternshipsDataContext())
        {
            Agency agency = dbContext.Agencies.Single(a => a.AgencyID == Convert.ToInt32((e.Item as GridEditableItem).GetDataKeyValue("AgencyID")));
            agency.AgencyDeleted = true;
            dbContext.SubmitChanges();
        }
    }
}
 
protected void rgPreRender(object sender, EventArgs e)
{
    RadGrid rg = sender as RadGrid;
    rg.Columns.FindByUniqueName("Buttons").Visible = UserInfo.IsInRole(PortalSettings.AdministratorRoleName);
}

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 22 Jul 2013, 04:17 PM
Hello,

For your scenario I would suggest you find the inner RadGrid in the nested item's ItemCreated event and attach a NeedDataSource event handler for it as shown below:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridNestedViewItem) 
    
        (e.Item.FindControl("InnerGridId") as RadGrid).NeedDataSource += new GridNeedDataSourceEventHandler(_Default_NeedDataSource); 
    
   
void _Default_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    //define inner grid data source. 
    // ((source as RadGrid).NamingContainer as GridNestedViewItem) gives a reference to the 
    //parent nested view item 

Try binding the grid using this approach and see if it helps.

Regards,
Pavlina
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Matthew
Top achievements
Rank 1
answered on 22 Jul 2013, 04:40 PM
The behavior is identical.

I noticed this solution elsewhere in the forums, but I didn't think it applied since I had specified the OnNeedDataSource method on the page. Regardless, I tried it with and without and the behavior is the same. I've since tried other things, but I've only managed to get the solid line(s) all the time instead of on a callback after the nested view is expanded.
0
Pavlina
Telerik team
answered on 25 Jul 2013, 03:47 PM
Hi Matthew,

Can you open formal support ticket and send us a sample project where the described issue can be observed, so we can advice you further?

Meanwhile you can check the attached project which demonstrates the suggested approach in the previous post.

Regards,
Pavlina
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Matthew
Top achievements
Rank 1
answered on 25 Jul 2013, 07:29 PM
Found the problem in the following method:

protected void rgSpecifications_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid rg = sender as RadGrid;
    GridDataItem item = ((GridNestedViewItem)rg.NamingContainer).ParentItem as GridDataItem;
    using (EXSCInternshipsDataContext dbContext = new EXSCInternshipsDataContext())
    {
        Agency agency = dbContext.Agencies.Single(a => a.AgencyID == Convert.ToInt32(item.GetDataKeyValue("AgencyID")));
        IEnumerable<InternshipSpecification> list = agency.InternshipSpecifications.ToList();
        if (list.Count() == 0) rg.Visible = UserInfo.IsInRole(PortalSettings.AdministratorRoleName);
        else rg.DataSource = agency.InternshipSpecifications.ToList();
    }
}

I don't have any specifications in the development database, so the if statement is always true and the RadGrid's DataSource is never set which I only now remember causes this behavior. I've corrected the code so that the DataSource is always set. Now the NoRecords template doesn't show initially, but the bigger problem has been dealt with. Thanks.
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or