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

[Solved] HeaderText on DetailTable disappears

3 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kim
Top achievements
Rank 1
Kim asked on 29 Apr 2013, 04:02 PM
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="NestedRadGrids.aspx.vb"
    Inherits="KimWebSandbox.NestedRadGrids" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="rsmJS" runat="server" EnablePageMethods="true"></telerik:RadScriptManager>
 
        <telerik:radgrid id="OuterGrid" runat="server" AutoGenerateColumns="false">
            <MasterTableView Name="Level1">
                <Columns>
                    <telerik:GridBoundColumn />
                    <telerik:GridBoundColumn DataField="Sales" HeaderText="Sales" UniqueName="Sales" />
                </Columns>
                <DetailTables>
                    <telerik:GridTableView Name="Level2" AutoGenerateColumns="false">
                            <Columns>
                                <telerik:GridBoundColumn />
                                <telerik:GridBoundColumn DataField="Sales" HeaderText="Sales" UniqueName="Sales" />
                            </Columns>
                             <DetailTables>
                                <telerik:GridTableView Name="Level3" AutoGenerateColumns="false">
                                        <Columns>
                                            <telerik:GridBoundColumn />
                                            <telerik:GridBoundColumn DataField="Sales" HeaderText="Sales" UniqueName="Sales" />
                                        </Columns>
                                </telerik:GridTableView>
                            </DetailTables>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
        </telerik:radgrid>
    </div>
    </form>
</body>
</html>

Imports Telerik.Web.UI
 
Public Class NestedRadGrids
    Inherits System.Web.UI.Page
 
    Private Sub OuterGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles OuterGrid.NeedDataSource
        If Not e.IsFromDetailTable Then
            OuterGrid.Columns(0).HeaderText = "Dept"
            DirectCast(OuterGrid.Columns(0), GridBoundColumn).DataField = "Dept"
            OuterGrid.DataSource = GetDataforGrid()
        End If
    End Sub
 
    Private Sub OuterGrid_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles OuterGrid.DetailTableDataBind
        Select Case e.DetailTableView.Name
            Case "Level2"
                e.DetailTableView.Columns(0).HeaderText = "Level 2 Header"
                DirectCast(e.DetailTableView.Columns(0), GridBoundColumn).DataField = "Dept"
                e.DetailTableView.DataSource = GetDataforGrid()
            Case "Level3"
                e.DetailTableView.Columns(0).HeaderText = "Level 3 Header"
                DirectCast(e.DetailTableView.Columns(0), GridBoundColumn).DataField = "Dept"
                e.DetailTableView.DataSource = GetDataforGrid()
        End Select
    End Sub
 
    Private Function GetDataforGrid() As DataSet
        Dim ds As New DataSet
        Dim dt As New DataTable
 
        dt.Columns.Add("Dept", GetType(String))
        dt.Columns.Add("Sales", GetType(String))
 
        dt.Rows.Add("10", "5749.00")
        dt.Rows.Add("11", "2123.00")
 
        ds.Tables.Add(dt)
        Return ds
    End Function
End Class

I need to be able to set the header text dynamically in the first column of my Detail Views.
If you run the code above, you will see that the outer table is correctly set to "Dept".
Expand the first row and you will see that the detail table is correctly set to "Level 2 Header".
Expand the first row in Level 2 and you will see that the next detail table is correctly set to "Level 2 Header".
HOWEVER, the header text in Level 2 disappears.


3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 02 May 2013, 12:43 PM
Hello Kim,

Since the DetailTableDataBind is fired differently depending on the HierarchyLoadMode I suggest that you move the logic which changes the headers text in the OnItemDataBound event of the grid. A sample demonstration of how this can be achieved is shown in the code snippet below:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
        Dim headerItem As GridHeaderItem
            headerItem = TryCast(e.Item, GridHeaderItem)
            If headerItem IsNot Nothing Then
            If headerItem.OwnerTableView.Name = "TheNameOfTheCurrentOwnerTableView" Then
                headerItem("column").Text = "theColumnNameText"
            End If
        End If
    End Sub


All the best,
Angel Petrov
the Telerik team
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 their blog feed now.
0
Kim
Top achievements
Rank 1
answered on 02 May 2013, 02:53 PM
I did not find this to be a working solution when the detail views are deeper than one level. Please try this new code behind. You will see that the same issue occurs with the header text disappearing.

Imports Telerik.Web.UI
 
Public Class NestedRadGrids
    Inherits System.Web.UI.Page
 
    Private Sub OuterGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles OuterGrid.ItemDataBound
        Dim headerItem As GridHeaderItem
        headerItem = TryCast(e.Item, GridHeaderItem)
        If headerItem IsNot Nothing Then
            If headerItem.OwnerTableView.Name = "Level2" Then
                headerItem("Level2Dept").Text = "Level 2 Header"
            ElseIf headerItem.OwnerTableView.Name = "Level3" Then
                headerItem("Level3Dept").Text = "Level 3 Header"
            End If
        End If
    End Sub
 
    Private Sub OuterGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles OuterGrid.NeedDataSource
        If Not e.IsFromDetailTable Then
            OuterGrid.Columns(0).HeaderText = "Dept"
            DirectCast(OuterGrid.Columns(0), GridBoundColumn).DataField = "Dept"
            OuterGrid.DataSource = GetDataforGrid()
        End If
    End Sub
 
    Private Sub OuterGrid_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles OuterGrid.DetailTableDataBind
        Select Case e.DetailTableView.Name
            Case "Level2"
                'e.DetailTableView.Columns(0).HeaderText = "Level 2 Header"
                DirectCast(e.DetailTableView.Columns(0), GridBoundColumn).UniqueName = "Level2Dept"
                DirectCast(e.DetailTableView.Columns(0), GridBoundColumn).DataField = "Dept"
                e.DetailTableView.DataSource = GetDataforGrid()
            Case "Level3"
                'e.DetailTableView.Columns(0).HeaderText = "Level 3 Header"
                DirectCast(e.DetailTableView.Columns(0), GridBoundColumn).UniqueName = "Level3Dept"
                DirectCast(e.DetailTableView.Columns(0), GridBoundColumn).DataField = "Dept"
                e.DetailTableView.DataSource = GetDataforGrid()
        End Select
    End Sub
 
    Private Function GetDataforGrid() As DataSet
        Dim ds As New DataSet
        Dim dt As New DataTable
 
        dt.Columns.Add("Dept", GetType(String))
        dt.Columns.Add("Sales", GetType(String))
 
        dt.Rows.Add("10", "5749.00")
        dt.Rows.Add("11", "2123.00")
 
        ds.Tables.Add(dt)
        Return ds
    End Function
 
End Class
0
Kim
Top achievements
Rank 1
answered on 02 May 2013, 03:06 PM
This code does seem to work:
Private Sub OuterGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles OuterGrid.ItemDataBound
    OuterGrid.MasterTableView.DetailTables(0).Columns(0).HeaderText = "Level 2 Header"
    OuterGrid.MasterTableView.DetailTables(0).DetailTables(0).Columns(0).HeaderText = "Level 3 Header"
End Sub
Tags
Grid
Asked by
Kim
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Kim
Top achievements
Rank 1
Share this question
or