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

usercontrol in nestedviewTemplate

6 Answers 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pravin Magdum
Top achievements
Rank 1
Pravin Magdum asked on 06 May 2010, 08:45 AM
hi all ,
i have radgrid on page with nestedviewTemplate , in nested view template i call user control (.ascx)
page size is 10 for mastertable 
in user control i have one radgrid . when i load page it goes in load event of user control for 10 times (page size of master table) 
and load the entire grid on user control 10 times .
it takes too long time ,so for any postback (syn/asyn) pointer go in user controls load method .
i dont want this scenario ,instead i want when user clicks on expand button only that time it should call the usercontrol for only taht record and fetch same data for record only instead of binding all data every time 

how should i go further ...looking for helping hands :) thnx in advance 

6 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 May 2010, 12:52 PM
Hello Pravin,

You can prevent populating the grid (placed in user control) for each items by setting the Visible property of grid on user control to "false". When the grid's Visible property is set to false, the NeedDataSource event of grid will not fire.

In ItemCommand event of parent grid, access the grid placed iin user control and set the Visible property to "True" and call the Rebind() method, which in turn invoke the NeedDataSource event to populate the grid. Here is the sample code.

C#:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.ExpandCollapseCommandName) 
    {      
        Usercontrol uc = (Usercontrol)((GridDataItem)e.Item).ChildItem.FindControl("Usercontrol1"); 
        RadGrid gridinUC = (RadGrid)uc.FindControl("RadGridinUC"); 
        if (!e.Item.Expanded) 
        { 
            gridinUC.Visible = true
            gridinUC.Rebind(); 
        } 
        else 
        { 
            gridinUC.Visible = false
        } 
    }  


Hope this suggestion helps,
Shinu.
0
Pravin Magdum
Top achievements
Rank 1
answered on 06 May 2010, 04:03 PM
hi shinu ..
gr8 work.. thnx a ton..

i have small  issue ..after clicking on expanded arrow it doesnt get closed i modified ur code little bt seems i miss some thing 
please correct ..

foreach (GridDataItem item in RadGrid_ShowTripPlan.Items) 
        { 
            if (!item.Expanded) 
                item.Expanded = false
             
        } 
        if (e.CommandName == Telerik.Web.UI.RadGrid.ExpandCollapseCommandName) 
        { 
            UserControl uc = (UserControl)((GridDataItem)e.Item).ChildItem.FindControl("uc1"); 
            Telerik.Web.UI.RadGrid gridinUC = (Telerik.Web.UI.RadGrid)uc.FindControl("RadGrid1"); 
 
            if (!e.Item.Expanded) 
            { 
                gridinUC.Visible = true
                gridinUC.Rebind(); 
            } 
            else 
            {    
                e.item.Expanded =false
                gridinUC.Visible = false;                                 
            } 
        } 
 
bt it doesnt works :( 



0
Shinu
Top achievements
Rank 2
answered on 07 May 2010, 09:20 AM
Hello Pravin,

I am not sure about the issue that you described. I did experience a similar issue after I added "e.item.Expanded =false;" as in your code.

Could you please elaborate on the issue that you are facing?

-Shinu.
0
Pravin Magdum
Top achievements
Rank 1
answered on 07 May 2010, 10:07 AM
hello shinu ,
thnx for response

in commanitem of master grid , i made some changes .

scenario which i want is liek user can open only one nested view template at a time which i achived  using foreach loop i set all items expanded to false .

now if any item is expanded if i click on same item it should be closed which i am not getting

i checked the condition as stated  in previous post code snippet .

issue i am facing is it goes to else part execute the statement "e.item.Expanded =false" but it didnt set it as collapsed .it  remain expanded.
thnx in advance :)
0
Pravin Magdum
Top achievements
Rank 1
answered on 19 May 2010, 04:50 PM
any one ?????

0
Isaac
Top achievements
Rank 1
answered on 12 Apr 2017, 11:06 AM

Shinu,

Thank you very much for this post. I initially placed my codes inside the ItemDataBound Event of the RadGrid, I could not find my user control, but with your post, I moved my code to ItemCommand which I actually suspected my help, the my codes worked.

 

protected void grdView_ItemCommand(object source, GridCommandEventArgs e)
{
        if (e.CommandName == RadGrid.ExpandCollapseCommandName)
       {     
          var grid = (ASP.app_idd_usercontrol_oduediligenceaudittrail_ascx) ((GridDataItem) e.Item).ChildItem.FindControl("oDueDiligenceAuditTrail");
            if (!e.Item.Expanded)
           {
               long lRequestId = long.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["REQUESTID"].ToString());
              grid.ViewAuditTrail(lRequestId);
           }
      }

}

 

Thank you.

 

 

Tags
Grid
Asked by
Pravin Magdum
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Pravin Magdum
Top achievements
Rank 1
Isaac
Top achievements
Rank 1
Share this question
or