6 Answers, 1 is accepted
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.
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; |
} |
} |
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.
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 :)
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.