I have a telerik datagrid and I would like to hide the collapse button when there are no childs available. It does not work as I would aspect.
This is my code :
my C# code behind :
The BLogic.ITTickets.GetStructure(null, null, 0); calls a stored procedure on sql server that gives me back the list with the data.
Can anyone please tell me what I do wrong?
Kind regards
Suzy
This is my code :
<
telerik:RadGrid
ID
=
"grdTest"
runat
=
"server"
AutoGenerateColumns
=
"false"
PageSize
=
"20"
AllowSorting
=
"true"
AllowPaging
=
"true"
ShowGroupPanel
=
"true"
ShowFooter
=
"true"
MasterTableView-HierarchyDefaultExpanded
=
"true"
OnNeedDataSource
=
"grdTest_NeedDataSource"
OnItemCreated
=
"grdTest_ItemCreated"
OnPreRender
=
"grdTest_PreRender"
>
<
MasterTableView
AllowSorting
=
"true"
DataKeyNames
=
"TicketID, TopTicketID"
Width
=
"100%"
HierarchyLoadMode
=
"ServerBind"
>
<
SelfHierarchySettings
ParentKeyName
=
"TopTicketID"
KeyName
=
"TicketID"
/>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"TicketID"
HeaderText
=
"Ticket"
HeaderButtonType
=
"TextButton"
DataField
=
"TicketID"
UniqueName
=
"TicketID"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowExpandCollapse
=
"true"
></
ClientSettings
>
</
telerik:RadGrid
>
my C# code behind :
protected void grdTest_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
grdTest.DataSource = BLogic.ITTickets.GetStructure(null, null, 0);
}
protected void grdTest_PreRender(object sender, EventArgs e)
{
HideExpandColumnRecursive(grdTest.MasterTableView);
}
public void HideExpandColumnRecursive(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
{
foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
{
if (nestedView.Items.Count == 0)
{
TableCell cell = nestedView.ParentItem["ExpandColumn"];
cell.Controls[0].Visible = false;
cell.Text = " ";
nestedViewItem.Visible = false;
}
if (nestedView.HasDetailTables)
{
HideExpandColumnRecursive(nestedView);
}
}
}
}
The BLogic.ITTickets.GetStructure(null, null, 0); calls a stored procedure on sql server that gives me back the list with the data.
Can anyone please tell me what I do wrong?
Kind regards
Suzy