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

Accessing ItemTemplate Items

3 Answers 266 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Ricky
Top achievements
Rank 2
Ricky asked on 11 Aug 2008, 12:32 AM
Hi

I am using a RadPanelbar and in the <ItemTemplate> i am using the Literal. so in C# how can i access the literal.

it will be  RadPanelbar.FindControl("ABC")  but don;t know the c# code for declaring the instance.

Thanks
Ricky

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Aug 2008, 12:51 PM
Hi Ricky,

Try accessing the control in the ItemTemplate as shown below.

ASPX:
<telerik:RadPanelBar ID="RadPanelBar1" runat="server" OnItemDataBound="RadPanelBar1_ItemDataBound" OnPreRender="RadPanelBar1_PreRender">   
        <ItemTemplate> 
            <asp:Literal ID="Literal1" runat="server"></asp:Literal> 
        </ItemTemplate> 
        </telerik:RadPanelBar> 

CS:
protected void RadPanelBar1_PreRender(object sender, EventArgs e)  
    {  
        foreach (RadPanelItem panelitem in RadPanelBar1.Items)  
        {  
            Literal lit = (Literal)panelitem.FindControl("Literal1");  
        }  
    } 


Regards
Princy.
0
Paul
Telerik team
answered on 11 Aug 2008, 12:57 PM
Hello Ricky,

The FindControl method provides you with a reference to any control inside any of the templates used in the RadPanelBar or any of its PanelItems. You must make sure that you properly typecast the returned value as FindControl returns a reference to a Control class.

After you get the reference you may modify any properties of the referenced control. For details on the matter, please take a look at the following example - Accessing Nested Controls.

Best wishes,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Chase Florell
Top achievements
Rank 1
answered on 13 Aug 2008, 05:58 AM
EDIT >> SOLVED
Looks like you have to make sure that the Value="whatever" is in the right RadPanelItem... my bad




I have tried the info layed out in the example but I cannot figure out how to bind data to my grid which is nested inside a PanelBar.

        'Get BizForSale By User data from Database  
        Dim grdForSaleFind As RadGrid = DirectCast(RadPanelBar1.FindItemByValue("ForSaleAdmin").FindControl("grdBizForSaleAdmin"), RadGrid)  
        Dim BizForSaleAdminDC As New DAL.BizForSaleDataContext  
        Dim ForSaleAdminResults = BizForSaleAdminDC.bt_BizForSale_GetAll()  
        grdForSaleFind.DataSource = ForSaleAdminResults  
        grdForSaleFind.DataBind()  
 
 
 
        'Get BizForSale By User data from Database  
        Dim grdWantedFind As RadGrid = DirectCast(RadPanelBar1.FindItemByValue("WantedAdmin").FindControl("grdBizWantedAdmin"), RadGrid)  
        Dim BizWantedAdminDC As New DAL.BizWantedDataContext  
        Dim WantedAdminResults = BizWantedAdminDC.bt_BizWanted_GetAll()  
        grdWantedFind.DataSource = WantedAdminResults  
        grdWantedFind.DataBind() 

Error I receive is:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 114:        Dim BizForSaleAdminDC As New DAL.BizForSaleDataContext
Line 115:        Dim ForSaleAdminResults = BizForSaleAdminDC.bt_BizForSale_GetAll()
Line 116: grdForSaleFind.DataSource = ForSaleAdminResultsLine 117:        grdForSaleFind.DataBind()
Line 118:
Tags
PanelBar
Asked by
Ricky
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Paul
Telerik team
Chase Florell
Top achievements
Rank 1
Share this question
or