5 Answers, 1 is accepted
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| RadGrid1.MasterTableView.HierarchyDefaultExpanded = true; |
| foreach (GridTableView gtv in RadGrid1.MasterTableView.DetailTables) |
| gtv.HierarchyDefaultExpanded = true; |
| } |
| } |
Thanks for the snippet but when I use this code, code in the data_bound is getting faild
protected
void radgrdCompliance_DataBound(object sender, EventArgs e)
{
foreach (GridDataItem item in radgrdCompliance.Items)
{
HyperLink prodnameLnk = (HyperLink)item["ProductName"].FindControl("ProdNameLnk"); ==> this is working earliber but when i use the code snippet , HiearchyExpanded = true, its failing, seems its trying to loop thru the child items as well how to fix this issue ?
HiddenField hd = (HiddenField)item["ProductName"].FindControl("hdnpid");
prodnameLnk.NavigateUrl =
Constants.ProductDetailsPage + "?" + Constants.qspProductId + "=" + hd.Value;
}
}
alslo do i need set any property in the aspx file ? currently
HierarchyLoadMode
="ServerBind"
added the code in pre_render but no luck. it not showing in expanded mode only the > is changed "expanded mode
protected
void radgrdCompliance_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
radgrdCompliance.MasterTableView.HierarchyDefaultExpanded =
true;
foreach (GridTableView gtv in radgrdCompliance.MasterTableView.DetailTables)
{ gtv.HierarchyDefaultExpanded =
true; }
}
}
If you want the code inside the OnDataBound handle to be executed for items in the master table only, your foreach loop should be modified as follows:
foreach (GridDataItem item in radgrdCompliance.MasterTableView.Items)
Additionally, the more convenient approach to set HierarchyDefaultExpanded = true for each level of the hierarchy would be directly in the grid markup as part of the MasterTableView/GridTableView tags. You may also be interested in this documentation topic which explains how to traverse grid items/tables in hierarchical grid.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Also the code that you have implemented in the PreRender event, should work if your rebind your grid as shown below:
c#:
| protected void radgrdCompliance_PreRender(object sender, EventArgs e) |
| { |
| if (!Page.IsPostBack) |
| { |
| radgrdCompliance.MasterTableView.HierarchyDefaultExpanded = true; |
| foreach (GridTableView gtv in radgrdCompliance.MasterTableView.DetailTables) |
| { gtv.HierarchyDefaultExpanded = true; } |
| radgrdCompliance.Rebind(); |
| } |
| } |
Hope this helps..
Princy.