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

Grid / Hierarchy with Templates and Dynamic TabStrip

5 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 17 Jun 2010, 09:50 PM
Hello,

I am emulating the demo for the Hierarchy with Templates in the RadGrid except I want to create my tabs programatically.  The problem is when I need to access the RadTabStrip and the RadMultiPage controls within my codebehind functions for AddTab and AddPageView, I am not able to access thsoe controls.  I get a "object reference not set to an instance of an object" error.

I tried declaring the controls using FindControl but that doesn't seem to work:

Dim

 

RadTabStrip1 As RadTabStrip = CType(RadGrid1.FindControl("RadTabStrip1"), RadTabStrip)

So basically I need to know how to access controls in a NestedViewTemplate from the codebehind.

Thanks,

Steve

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 18 Jun 2010, 09:45 AM
Hi Steve,

Here is the code snippet if you want to access the RadStrip control in ItemDataBound/ItemCreated event.

C#:
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridNestedViewItem) 
        { 
            GridNestedViewItem nestedItem = (GridNestedViewItem)e.Item; 
            RadTabStrip tabStrip1 = (RadTabStrip)nestedItem.FindControl("RadTabStrip1"); 
            tabStrip1.SelectedIndex = 1; 
        } 
    } 


And the code snippet below shows, how to access the control any other postback event, outside grid.
C#:
 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach(GridNestedViewItem nestedItem in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
        { 
            RadTabStrip tabStrip1 = (RadTabStrip)nestedItem.FindControl("RadTabStrip1"); 
            tabStrip1.SelectedIndex = 2; 
        } 
    } 

And realted aspx is shown below.
 
<MasterTableView EditMode="EditForms" CommandItemDisplay="Top" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1"
        <NestedViewTemplate> 
            <telerik:RadTabStrip ID="RadTabStrip1" runat="server"
                <Tabs> 
                  . . . 
                </Tabs> 
            </telerik:RadTabStrip> 
        </NestedViewTemplate> 


-Shinu.
0
Stephen
Top achievements
Rank 1
answered on 18 Jun 2010, 03:10 PM
That did it thank you!  Now I have another question.  What I am trying to do as it relates to the demo is when the item from the outer grid is selected, it dynamically loads the tabs as you have helped me to do.  My tabs are loading user controls.  The user control requires the ID (which is the DataKey from the grid) from the selected row of the grid in order to load the correct information in the control.  In the case of the demo, I basically need to be able to pass the EmployeeID to my dynamically loaded control.

The way I was originally doing it, my list page just passed the ID on the querystring to the detail page and the control on the detail page was able to access the ID form the querystring.  But I am trying to use this Grid Hierarchy to have it all on one page and I am not sure how to pass that ID to the user control now. 

I've got the ID as a property of the user control, but I can't seem to access the ID in the ItemCreated of the Grid when I am adding the user control to the tab...I have tried e.Item and everything that relates to it but I can't seem to find how to access the ID of that particular item.  In order to findcontrol the RadTabStrip I need to be in GridNestedViewItem but so far I have only been able to access the ID when I am in GridDataItem.
0
Accepted
Maria Ilieva
Telerik team
answered on 23 Jun 2010, 02:56 PM
Hi Stephen,

Please note that you will not be able ot get the ID of the GridNestedViewItem in the ItemCreated event, as the items are still not loaded in the Grid. For this purpose you should use the ItemDataBound event and get the ID like this:

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
{  
    if (e.Item is GridNestedViewItem)  
    {  
        GridNestedViewItem nestedItem = (GridNestedViewItem)e.Item;  
        GridDataItem parentItem = nestedItem.ParentItem;
        string id = parentItem.GetDataKeyValue("ID").ToString();
    }  
}

I hope this helps.

Greetings,
Maria Ilieva
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 23 Jun 2010, 09:44 PM
Thank you!  That answered that question.  I used that logic to workout another issue as well.

I still have two problems with what I am trying to do.  I have posted a new Thread here: http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-hierarchy-and-on-demand-tabstrip-pageview.aspx#1242595

I would appreciate any help with that.

thanks!
0
Sebastian
Telerik team
answered on 24 Jun 2010, 11:42 AM
Hello Stephen,

We will review your other forum post and will respond in the same thread.
 
Kind regards,
Sebastian
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
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Stephen
Top achievements
Rank 1
Maria Ilieva
Telerik team
Sebastian
Telerik team
Share this question
or