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

Grid Hierarchy and On Demand TabStrip/PageView

14 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 22 Jun 2010, 05:23 PM
Hello,

I am trying to combine two of the demos into one application and I am running into trouble.  I am doing the same thing as the RadGrid Hierarchy with Templates.  When an item in the grid is selected and it loads the nesteditem, I want to load my tabs and pageviews dynamically with user controls as in the TabStrip / Load on Demand RadPageView demo. I am having a coupld of problems with this:

1. How can I add the tabs only to the item that is being selected from the grid?  I have tried calling the addtab function from the ItemCreated and ItemDataBound methods of the RadGrid but of course it creates the tabs for every item (and also the pageview for the first tab) and I get the "multiple controls with the same ID" error.  If I try to call the addtab from the ItemCommand method of the RadGrid, it works the first time through but as soon as I try to collapse the current item it throws the same error.

2. When the PageViewCreated method fires and loads the user control onto the page, I need to be able to set a public property of that user control.  As it relates to the Telerik expample, I would need to be able to get the EmployeeID from the grid and assign it to the control (as the control needs that ID to load its data).  At the point where the pageview is being created, I can't figure out how to find the EmployeeID for that particular grid item.  I have tried using the DataKeyValues but I can't figure out how to get the index of the particular item that is selected on the grid as it is not being passed to the RadMultiPage controls PageViewCreated method.

Here is my aspx code:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadTabStrip1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadMultiPage1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting>              
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />         
      
    <script type="text/javascript">    
    function onTabSelecting(sender, args) {  
        if (args.get_tab().get_pageViewID()) {  
            args.get_tab().set_postBack(false);  
        }  
    }          
    </script>      
 
    <h4>Attendee List</h4>   
         
    <asp:ObjectDataSource ID="odsAttendeeList" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="dsAttendeeList" TypeName="WorkshopsLibrary.CAttendees">  
        <SelectParameters> 
            <asp:SessionParameter Name="sUserID" SessionField="UserID" Type="String" /> 
            <asp:SessionParameter Name="sWorkshopID" SessionField="AdminWorkshopID" Type="String" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 
      
    <telerik:RadGrid ID="RadGrid1" DataSourceID="odsAttendeeList" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnPreRender="RadGrid1_PreRender">  
        <PagerStyle Mode="NumericPages" /> 
        <MasterTableView DataSourceID="odsAttendeeList" DataKeyNames="RegistrationID" AllowMultiColumnSorting="True" GroupLoadMode="Server">  
            <NestedViewTemplate> 
                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false">  
                    <telerik:RadTabStrip ID="RadTabStrip1" SelectedIndex="0" CssClass="tabStrip" runat="server" MultiPageID="RadMultiPage1" Orientation="HorizontalTop" OnClientTabSelecting="onTabSelecting" OnTabClick="RadTabStrip1_TabClick" /> 
                    <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" CssClass="multiPage" OnPageViewCreated="RadMultiPage1_PageViewCreated" /> 
                </asp:Panel> 
            </NestedViewTemplate>                      
            <Columns> 
                <telerik:GridBoundColumn SortExpression="RegistrationID" HeaderText="RegistrationID" HeaderButtonType="TextButton" DataField="RegistrationID" UniqueName="RegistrationID" /> 
                <telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First Name" HeaderButtonType="TextButton" DataField="FirstName" UniqueName="FirstName" /> 
                <telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last Name" HeaderButtonType="TextButton" DataField="LastName" UniqueName="LastName" /> 
                <telerik:GridBoundColumn SortExpression="Citizenship" HeaderText="Citizenship" HeaderButtonType="TextButton" DataField="Citizenship" UniqueName="Citizenship" /> 
                <telerik:GridBoundColumn SortExpression="Phone" HeaderText="Phone" HeaderButtonType="TextButton" DataField="Phone" UniqueName="Phone" /> 
                <telerik:GridBoundColumn SortExpression="Email" HeaderText="Email" HeaderButtonType="TextButton" DataField="Email" UniqueName="Email" /> 
                <telerik:GridBoundColumn SortExpression="Cancelled" HeaderText="Cancelled" HeaderButtonType="TextButton" DataField="Cancelled" UniqueName="Cancelled" /> 
                <telerik:GridBoundColumn SortExpression="Accepted" HeaderText="Accepted" HeaderButtonType="TextButton" DataField="Accepted" UniqueName="Accepted" />                                                                  
            </Columns> 
        </MasterTableView> 
        <ClientSettings AllowDragToGroup="true" /> 
    </telerik:RadGrid> 

And here is my codebehind:

    Protected WithEvents RadTabStrip1 As RadTabStrip  
    Protected WithEvents RadMultiPage1 As RadMultiPage  
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
 
        Dim cPageRoutines As New CPageRoutines  
        Dim cWorkshops As New CWorkshops  
 
        If HttpContext.Current.Session("UserID") Is Nothing Then  
            cPageRoutines.Login(User)  
        End If  
        cPageRoutines.VerifyRole("SystemAdministrator")  
        cPageRoutines.VerifyAdminWorkshop("AdminWorkshopID")  
 
    End Sub  
 
    Private Sub AddPageView(ByVal tab As RadTab)  
 
        For Each nestedItem As GridNestedViewItem In RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)  
            Dim RadMultiPage1 As RadMultiPage = DirectCast(nestedItem.FindControl("RadMultiPage1"), RadMultiPage)  
            Dim pageView As RadPageView = New RadPageView  
            pageView.ID = tab.Text.Replace(" ", "")  
            RadMultiPage1.PageViews.Add(pageView)  
            pageView.CssClass = "pageView" 
            tab.PageViewID = pageView.ID  
        Next  
 
    End Sub  
 
    Private Sub AddTab(ByVal tabName As String)  
 
        For Each nestedItem As GridNestedViewItem In RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)  
            Dim RadTabStrip1 As RadTabStrip = DirectCast(nestedItem.FindControl("RadTabStrip1"), RadTabStrip)  
            Dim tab As RadTab = New RadTab  
            tab.Text = tabName 
            RadTabStrip1.Tabs.Add(tab)  
        Next  
 
    End Sub  
 
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender  
 
        If Not Page.IsPostBack Then  
            RadGrid1.MasterTableView.Items(0).Expanded = False 
            RadGrid1.MasterTableView.Items(0).ChildItem.FindControl("InnerContainer").Visible = True 
        End If  
 
    End Sub  
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand  
 
        If e.CommandName = RadGrid.ExpandCollapseCommandName Then  
            DirectCast(e.Item, GridDataItem).ChildItem.FindControl("InnerContainer").Visible = Not e.Item.Expanded  
        End If  
 
    End Sub  
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated  
 
        If TypeOf e.Item Is GridNestedViewItem Then  
            e.Item.FindControl("InnerContainer").Visible = (DirectCast(e.Item, GridNestedViewItem)).ParentItem.Expanded  
 
            Dim nestedItem As GridNestedViewItem = DirectCast(e.Item, GridNestedViewItem)  
            Dim RadTabStrip1 As RadTabStrip = DirectCast(nestedItem.FindControl("RadTabStrip1"), RadTabStrip)  
            AddTab("Attendee")  
            AddPageView(RadTabStrip1.FindTabByText("Attendee"))  
            AddTab("Additional Questions")  
            Dim cCustomFields As New CCustomFields  
            Dim dt As DataTable = cCustomFields.dsCustomFieldList(HttpContext.Current.Session("UserID").ToString, HttpContext.Current.Session("AdminWorkshopID").ToString).Tables(0)  
            If dt.Rows.Count > 0 Then  
                AddTab("Additional Questions")  
            End If  
            AddTab("Orders")  
            AddTab("Payments")  
        End If  
 
    End Sub  
 
    Protected Sub RadMultiPage1_PageViewCreated(ByVal sender As Object, ByVal e As RadMultiPageEventArgs) Handles RadMultiPage1.PageViewCreated  
 
        Dim userControlName As String = e.PageView.ID & ".ascx"  
        Dim userControl As Control = Page.LoadControl(userControlName)  
        userControl.ID = e.PageView.ID & "_userControl"  
        userControl.GetType().GetProperty("RegistrationID").SetValue(userControl, RadGrid1.MasterTableView.DataKeyValues(??)("RegistrationID").ToString, Nothing)  
        e.PageView.Controls.Add(userControl)  
 
    End Sub  
 
    Protected Sub RadTabStrip1_TabClick(ByVal sender As Object, ByVal e As RadTabStripEventArgs) Handles RadTabStrip1.TabClick  
 
        AddPageView(e.Tab)  
        e.Tab.PageView.Selected = True 
 
    End Sub 

14 Answers, 1 is accepted

Sort by
0
Stephen
Top achievements
Rank 1
answered on 23 Jun 2010, 09:42 PM
updated codebehind code to show tabs created during the grids ItemCommand method instead of the ItemCreated method:

    Protected WithEvents RadTabStrip1 As RadTabStrip  
    Protected WithEvents RadMultiPage1 As RadMultiPage  
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
 
        Dim cPageRoutines As New CPageRoutines  
        Dim cWorkshops As New CWorkshops  
 
        If HttpContext.Current.Session("UserID") Is Nothing Then  
            cPageRoutines.Login(User)  
        End If  
        cPageRoutines.VerifyRole("SystemAdministrator")  
        cPageRoutines.VerifyAdminWorkshop("AdminWorkshopID")  
 
    End Sub  
 
    Private Sub AddPageView(ByVal tab As RadTab)  
 
        For Each nestedItem As GridNestedViewItem In RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)  
            Dim RadMultiPage1 As RadMultiPage = DirectCast(nestedItem.FindControl("RadMultiPage1"), RadMultiPage)  
            Dim pageView As RadPageView = New RadPageView  
            pageView.ID = tab.Text.Replace(" ", "")  
            RadMultiPage1.PageViews.Add(pageView)  
            pageView.CssClass = "pageView" 
            tab.PageViewID = pageView.ID  
        Next  
 
    End Sub  
 
    Private Sub AddTab(ByVal tabName As String)  
 
        For Each nestedItem As GridNestedViewItem In RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)  
            Dim RadTabStrip1 As RadTabStrip = DirectCast(nestedItem.FindControl("RadTabStrip1"), RadTabStrip)  
            Dim tab As RadTab = New RadTab  
            tab.Text = tabName 
            RadTabStrip1.Tabs.Add(tab)  
        Next  
 
    End Sub  
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand  
 
        If e.CommandName = RadGrid.ExpandCollapseCommandName Then  
            DirectCast(e.Item, GridDataItem).ChildItem.FindControl("InnerContainer").Visible = Not e.Item.Expanded  
 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            Dim nestedItem As GridNestedViewItem = item.ChildItem  
            Dim RadTabStrip1 As RadTabStrip = DirectCast(nestedItem.FindControl("RadTabStrip1"), RadTabStrip)  
            AddTab("Attendee")  
            AddPageView(RadTabStrip1.FindTabByText("Attendee"))  
            AddTab("Additional Questions")  
            Dim cCustomFields As New CCustomFields  
            Dim dt As DataTable = cCustomFields.dsCustomFieldList(HttpContext.Current.Session("UserID").ToString, HttpContext.Current.Session("AdminWorkshopID").ToString).Tables(0)  
            If dt.Rows.Count > 0 Then  
                AddTab("Additional Questions")  
            End If  
            AddTab("Orders")  
            AddTab("Payments")  
        End If  
 
    End Sub  
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated  
 
        If TypeOf e.Item Is GridNestedViewItem Then  
            e.Item.FindControl("InnerContainer").Visible = (DirectCast(e.Item, GridNestedViewItem)).ParentItem.Expanded  
        End If  
 
    End Sub  
 
    Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
 
        If TypeOf e.Item Is GridNestedViewItem Then  
            Dim nestedItem As GridNestedViewItem = DirectCast(e.Item, GridNestedViewItem)  
        End If  
 
    End Sub  
 
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender  
 
        If Not Page.IsPostBack Then  
            RadGrid1.MasterTableView.Items(0).Expanded = False 
            RadGrid1.MasterTableView.Items(0).ChildItem.FindControl("InnerContainer").Visible = True 
        End If  
 
    End Sub  
 
    Protected Sub RadMultiPage1_PageViewCreated(ByVal sender As Object, ByVal e As RadMultiPageEventArgs) Handles RadMultiPage1.PageViewCreated  
 
        Dim userControlName As String = e.PageView.ID & ".ascx"  
        Dim userControl As Control = Page.LoadControl(userControlName)  
        userControl.ID = e.PageView.ID & "_userControl"  
        userControl.GetType().GetProperty("RegistrationID").SetValue(userControl, RadGrid1.MasterTableView.DataKeyValues(0)("RegistrationID").ToString, Nothing)  
        e.PageView.Controls.Add(userControl)  
 
    End Sub  
 
    Protected Sub RadTabStrip1_TabClick(ByVal sender As Object, ByVal e As RadTabStripEventArgs) Handles RadTabStrip1.TabClick  
 
        AddPageView(e.Tab)  
        e.Tab.PageView.Selected = True 
 
    End Sub 
0
Tsvetoslav
Telerik team
answered on 25 Jun 2010, 11:57 AM
Hi Stephen,

Straight to your questions.

1. I am afraid the LoadOnDemand scenario is not supported by the RadGrid control when a NestedViewTemplate is used.

2. To get the parent item's data key value you can use the following approach:

((GridNestedViewItem)e.PageView.MultiPage.NamingContainer).ParentItem.GetDataKeyValue("YourDataKeyID");

I hope this information helps.

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 1
answered on 25 Jun 2010, 03:54 PM
Ok thank you for the reply.  So is it still possible to have the a user control on the PageView for the tab (as opposed to having all of the code in the PageView) in this scenario, even if it is not OnDemand? And if so, how/when can I assign the DataKeyValue of that grid item to the public property of the control?
0
Tsvetoslav
Telerik team
answered on 30 Jun 2010, 03:17 PM
Hello Stephen,

It is possible to have a user control within the PageView. Just register the tagname and tagprefix for the control in the page directive and put the control in the page view. Alternatively, you can load it dynamically in code behind.

Concerning your second question, upon selecting an item you can intercept the SelectedIndexChanged event of the grid and get hand on the selected item through the incoming event args object. Having obtained a reference to the selected item you can easily get the data key and assign it to the desired property of the control: ((GridDataItem)e.Item).GetDataKeyValue("YourDataKeyName")....

Do let us know if you need further assistance.

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 1
answered on 07 Jul 2010, 07:19 PM
Hello again,

Thank you for your responses.  I am still stuck so to clarify, can I have a user control within the PageView when using the RadGrid with NestedViewTemplates?  You said in the previous post that the LoadOnDemand method will not work for the RadGrid with NestedViewTemplates but can I do it with registering the control on the page?  If so, when in the life cycle do I assign the property of the user control with the grid item ID?  The SelectedIndexChanged method obviously only fires when the item is selected on the grid, but the user control needs that when the grid itself is loading and gets to that user control, before the page has even rendered.

Maybe I am still missing something?

Here is my page:

<%@ Register TagPrefix="uc" TagName="LeftNav" Src="~/includes/navs/sysadmin.ascx" %> 
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI"  %>         
<%@ Register TagPrefix="uc" TagName="Attendee" Src="~/attendee.ascx" %> 
 
 
<asp:Content ID="Content1" ContentPlaceHolderID="NavContentPlaceHolder" runat="server">  
    <div id="nav">  
    <uc:LeftNav id="LeftNav" runat="server" /> 
    <p><img border="0" src="/images/spacer.gif" height="1" alt=""></p> 
    </div> 
</asp:Content> 
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">  
               
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadTabStrip1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadMultiPage1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting>              
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />         
      
    <script type="text/javascript">    
    function onTabSelecting(sender, args) {  
        if (args.get_tab().get_pageViewID()) {  
            args.get_tab().set_postBack(false);  
        }  
    }          
    </script>      
 
    <h4>Attendee List</h4>   
         
    <asp:ObjectDataSource ID="odsAttendeeList" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="dsAttendeeList" TypeName="WorkshopsLibrary.CAttendees">  
        <SelectParameters> 
            <asp:SessionParameter Name="sUserID" SessionField="UserID" Type="String" /> 
            <asp:SessionParameter Name="sWorkshopID" SessionField="AdminWorkshopID" Type="String" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 
      
    <telerik:RadGrid ID="RadGrid1" DataSourceID="odsAttendeeList" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnPreRender="RadGrid1_PreRender">  
        <PagerStyle Mode="NumericPages" /> 
        <MasterTableView DataSourceID="odsAttendeeList" DataKeyNames="RegistrationID" AllowMultiColumnSorting="True" GroupLoadMode="Server">  
            <NestedViewTemplate> 
                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false">  
                    <telerik:RadTabStrip runat="server" ID="RadTabStip1" MultiPageID="RadMultiPage1" SelectedIndex="0">  
                        <Tabs> 
                            <telerik:RadTab runat="server" Text="Attendee" PageViewID="PageView1" /> 
                        </Tabs> 
                    </telerik:RadTabStrip> 
                    <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0" RenderSelectedPageOnly="false">  
                        <telerik:RadPageView runat="server" ID="PageView1">  
                            <uc:Attendee ID="ctlAttendee" runat="server" /> 
                        </telerik:RadPageView> 
                    </telerik:RadMultiPage> 
                </asp:Panel> 
            </NestedViewTemplate>                      
            <Columns> 
                <telerik:GridBoundColumn SortExpression="RegistrationID" HeaderText="RegistrationID" HeaderButtonType="TextButton" DataField="RegistrationID" UniqueName="RegistrationID" /> 
                <telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First Name" HeaderButtonType="TextButton" DataField="FirstName" UniqueName="FirstName" /> 
                <telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last Name" HeaderButtonType="TextButton" DataField="LastName" UniqueName="LastName" /> 
                <telerik:GridBoundColumn SortExpression="Citizenship" HeaderText="Citizenship" HeaderButtonType="TextButton" DataField="Citizenship" UniqueName="Citizenship" /> 
                <telerik:GridBoundColumn SortExpression="Phone" HeaderText="Phone" HeaderButtonType="TextButton" DataField="Phone" UniqueName="Phone" /> 
                <telerik:GridBoundColumn SortExpression="Email" HeaderText="Email" HeaderButtonType="TextButton" DataField="Email" UniqueName="Email" /> 
                <telerik:GridBoundColumn SortExpression="Cancelled" HeaderText="Cancelled" HeaderButtonType="TextButton" DataField="Cancelled" UniqueName="Cancelled" /> 
                <telerik:GridBoundColumn SortExpression="Accepted" HeaderText="Accepted" HeaderButtonType="TextButton" DataField="Accepted" UniqueName="Accepted" />                                                                  
            </Columns> 
        </MasterTableView> 
        <ClientSettings AllowDragToGroup="true" /> 
    </telerik:RadGrid>    
</asp:Content> 

And here is the code behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
 
        Dim cPageRoutines As New CPageRoutines  
        Dim cWorkshops As New CWorkshops  
 
        If HttpContext.Current.Session("UserID") Is Nothing Then  
            cPageRoutines.Login(User)  
        End If  
        cPageRoutines.VerifyRole("SystemAdministrator")  
        cPageRoutines.VerifyAdminWorkshop("AdminWorkshopID")  
 
    End Sub  
 
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender  
 
        If Not Page.IsPostBack Then  
            RadGrid1.MasterTableView.Items(0).Expanded = True 
            RadGrid1.MasterTableView.Items(0).ChildItem.FindControl("InnerContainer").Visible = True 
        End If  
 
    End Sub  
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand  
 
        If e.CommandName = RadGrid.ExpandCollapseCommandName Then  
            DirectCast(e.Item, GridDataItem).ChildItem.FindControl("InnerContainer").Visible = Not e.Item.Expanded  
        End If  
 
    End Sub  
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated  
 
        If TypeOf e.Item Is GridNestedViewItem Then  
            e.Item.FindControl("InnerContainer").Visible = (DirectCast(e.Item, GridNestedViewItem)).ParentItem.Expanded  
        ElseIf TypeOf e.Item Is GridDataItem Then  
            'Dim nestedItem As GridNestedViewItem = DirectCast(e.Item, GridNestedViewItem)  
            'Dim parentItem As GridDataItem = nestedItem.ParentItem  
            'Dim sRegistrationID As String = DirectCast(e.Item, GridDataItem).GetDataKeyValue("RegistrationID").ToString()  
            'Dim ctlAttendee As Control = DirectCast(nestedItem.FindControl("ctlAttendee"), Control)  
            'ctlAttendee.GetType().GetProperty("RegistrationID").SetValue(ctlAttendee, sRegistrationID, Nothing)  
        End If  
 
    End Sub  
 
    Private Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged  
 
        'Dim sRegistrationID As String = DirectCast(e.Item, GridDataItem).GetDataKeyValue("YourDataKeyName")  
        'Dim ctlAttendee As Control = DirectCast(DirectCast(e.Item, GridNestedViewItem).FindControl("ctlAttendee"), Control)  
        'ctlAttendee.GetType().GetProperty("RegistrationID").SetValue(ctlAttendee, sRegistrationID, Nothing)  
 
    End Sub 

Thank you again.
0
Tsvetoslav
Telerik team
answered on 12 Jul 2010, 10:32 AM
Hello Stephen,

Sorry for the misunderstanding - by loading on demand I got that you are trying to load the controls within the nested view template on demand and not the user control in the tab strip. Of course, if you need to load on demand the user control in the tab strip you can do so. I am sending you a small sample demonstrating the second approach - having the user control declared in the mark-up of the page and getting the grid ID in the OnLoad event.

Hope it helps.

All the best,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 1
answered on 12 Jul 2010, 08:39 PM

Thank you once again for the help.  I am almost there.  But the problem is that in the User Control I need the ID of the item within the grid that is loading the user control, not the ID of the grid itself.  The code you provided in the example on the pageload of the user control is providing the ID of the grid, not the item that is trying to load the user control...

Is it just a step further that I need to take using the code you provided? Having the ID of the grid maybe I can get the ID of the selected item?  I tried to do that in a couple of different ways by doing findcontrol on the Grid and trying to get the selecteditemvalue but I couldn't get it to work.

0
Stephen
Top achievements
Rank 1
answered on 12 Jul 2010, 09:59 PM
I think I figured it out based on the code you provided.  To get the value of the selected item (in your example the EmployeeID) on the grid that is loading the user control, I did the following:

Dim

 

parentItem As GridDataItem = DirectCast(Me.Parent.NamingContainer, Telerik.Web.UI.GridNestedViewItem).ParentItem

 

m_sRegistrationID = parentItem.GetDataKeyValue(

"RegistrationID").ToString()

This seems to be working for me.  If I am still doing something wrong please let me know.

thanks!

Steve

 

0
Atlas
Top achievements
Rank 1
answered on 15 Feb 2012, 06:40 PM
//Here is a working example in C#
using System;
using Telerik.Web.UI;
  
namespace RadControlsDynamicTabStrip.Shared.Control
{
    public partial class HeraDiversityCertificates : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var parentItem = ((GridNestedViewItem)(Parent.NamingContainer)).ParentItem;
            int brokerApplicationId = (int)parentItem.GetDataKeyValue("Id");
        }
    }
}
I am adding a working example here. I wish they would let you upload zip files to the forums.
<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/Master/Site.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="RadControlsDynamicTabStrip.Grid" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function onTabSelecting(sender, args) {
            if (args.get_tab().get_pageViewID()) {
                args.get_tab().set_postBack(false);
            }
        }
    </script>
  
    <style type="text/css">
            .viewWrap
            {
                padding: 5px;
                background: #e0e0e0;
            }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="true" Width="100%" GridLines="None"
        AutoGenerateColumns="False" AllowAutomaticDeletes="True" OnItemDataBound="RadGrid1_ItemDataBound"
        OnNeedDataSource="RadGrid1_NeedDataSource">
        <PagerStyle Mode="NextPrevAndNumeric" />
        <MasterTableView Width="100%" CommandItemDisplay="None" DataKeyNames="Id" HorizontalAlign="NotSet"
            AutoGenerateColumns="False">
            <NestedViewTemplate>
                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap">
                    <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1" />
                    <telerik:RadAjaxManagerProxy runat="server" ID="RadAjaxManagerProxy1">
                        <AjaxSettings>
                            <telerik:AjaxSetting AjaxControlID="RadTabStrip1">
                                <UpdatedControls>
                                    <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
                                </UpdatedControls>
                            </telerik:AjaxSetting>
                            <telerik:AjaxSetting AjaxControlID="RadMultiPage1">
                                <UpdatedControls>
                                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
                                </UpdatedControls>
                            </telerik:AjaxSetting>
                        </AjaxSettings>
                    </telerik:RadAjaxManagerProxy>
                    <telerik:RadTabStrip OnClientTabSelecting="onTabSelecting" ID="RadTabStrip1" SelectedIndex="0"
                        Width="100%" runat="server" MultiPageID="RadMultiPage1" OnTabClick="RadTabStrip1_TabClick"
                        Orientation="HorizontalTop" CausesValidation="false">
                    </telerik:RadTabStrip>
                    <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" OnPageViewCreated="RadMultiPage1_PageViewCreated" />
                </asp:Panel>
            </NestedViewTemplate>
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" ItemStyle-CssClass="cursorPointer" />
                <telerik:GridBoundColumn DataField="Id" UniqueName="Id" SortExpression="Id" HeaderText="Id"
                    ReadOnly="true" ItemStyle-Width="35px" />
                <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" SortExpression="FirstName"
                    HeaderText="First Name" MaxLength="128" />
                <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" SortExpression="LastName"
                    HeaderText="Last Name" MaxLength="128" />
                <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ConfirmText="Are you sure you want to delete this application?"
                    ItemStyle-CssClass="cursorPointer" ButtonType="ImageButton" />
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
    </telerik:RadGrid>
</asp:Content>

using System;
using System.Data;
using System.Web.UI;
using Telerik.Web.UI;
  
namespace RadControlsDynamicTabStrip
{
    public partial class Grid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
  
        }
  
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            DataTable dt = new DataTable();
              
            dt.Columns.Add("ID", Type.GetType("System.Int32"));
            dt.Columns.Add("FirstName", Type.GetType("System.String"));
            dt.Columns.Add("LastName", Type.GetType("System.String"));
  
            for (int x = 1; x <= 5; x++)
            {
                DataRow dr = dt.NewRow();
                dr["ID"] = x;
                dr["FirstName"] = string.Format("Joe {0}", x);
                dr["LastName"] = string.Format("Smith {0}", x);
                dt.Rows.Add(dr);
  
                RadGrid1.DataSource = dt;
            }
        }
  
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {
                RadTabStrip radTabStrip1 = (RadTabStrip)e.Item.FindControl("RadTabStrip1");
                RadMultiPage radMultiPage1 = (RadMultiPage)e.Item.FindControl("RadMultiPage1");
  
                if (radTabStrip1 != null)
                {
                    AddTab(radTabStrip1, "Personal Info");
                    AddTab(radTabStrip1, "License Info");
                    AddTab(radTabStrip1, "HERA");
                    AddTab(radTabStrip1, "HERA Diversity Certificates");
                    AddPageView(radMultiPage1, radTabStrip1.FindTabByText("Personal Info"));
                }
            }
        }
  
        private void AddTab(RadTabStrip radTabStrip1, string tabName)
        {
            var tab = new RadTab { Text = tabName };
            radTabStrip1.Tabs.Add(tab);
        }
  
        protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)
        {
            //The file name is the tab name with any spaces removed.
            string userControlName = "~/Shared/Control/" + e.PageView.ID.Replace(" ", "") + ".ascx";
  
            Control userControl = Page.LoadControl(userControlName);
            userControl.ID = e.PageView.ID + "_userControl";
  
            e.PageView.Controls.Add(userControl);
        }
  
        private void AddPageView(RadMultiPage radMultiPage1, RadTab tab)
        {
            var pageView = new RadPageView { ID = tab.Text.Replace(" ", "") };
            radMultiPage1.PageViews.Add(pageView);
            pageView.CssClass = "pageView";
            tab.PageViewID = pageView.ID;
            tab.Selected = true;
        }
  
        protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)
        {
            AddPageView(((RadTabStrip)sender).MultiPage, e.Tab);
            e.Tab.PageView.Selected = true;
        }
  
    }
}

Above is the default.aspx page and code behind which is using a master page.
Below is the code behind for one of the user controls:
using System;
using Telerik.Web.UI;
  
namespace RadControlsDynamicTabStrip.Shared.Control
{
    public partial class HeraDiversityCertificates : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var parentItem = ((GridNestedViewItem)(Parent.NamingContainer)).ParentItem;
            int brokerApplicationId = (int)parentItem.GetDataKeyValue("Id");
        }
    }
}
0
Tsvetoslav
Telerik team
answered on 20 Feb 2012, 05:02 PM
Hello Stephen,

Thanks for sharing your code.

Regards,
Tsvetoslav
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Atlas
Top achievements
Rank 1
answered on 20 Feb 2012, 07:48 PM
would it be possible for me to send you a zip file that you could attach to the bug?
I have a complete working example I would be happy to share.
0
Tsvetoslav
Telerik team
answered on 23 Feb 2012, 04:42 PM
Hi Nano,

You can open up a formal support ticket and attache your files to the ticket post.


Regards, Tsvetoslav
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
Atlas
Top achievements
Rank 1
answered on 23 Feb 2012, 05:54 PM
I did that, and suggested that you make a demo out of it, but that support ticket is not available to other users, and I would be really surprised if you added it to the demos.
0
Tsvetoslav
Telerik team
answered on 24 Feb 2012, 06:22 AM
Hello Stephen,

Apart from the online examples we have a section of code library examples. Please, upload it there and after approval we will official expose it to the public.

Thanks for that.


Greetings,
Tsvetoslav
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.
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Stephen
Top achievements
Rank 1
Tsvetoslav
Telerik team
Atlas
Top achievements
Rank 1
Share this question
or