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

Bind Item Templates during the ItemDataBound event

3 Answers 166 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Charles Meyer
Top achievements
Rank 1
Charles Meyer asked on 19 Aug 2009, 09:58 PM
OK, I am sure this is easier than I am making this out to be, but how do you bind the elements in the Item Template during the  ItemDataBound event? Here is my aspx code:
<telerik:RadPanelBar ID="RadPanelBar1" Width="100%" runat="server"   
    onitemdatabound="RadPanelBar1_ItemDataBound">                  
        <Items> 
            <telerik:RadPanelItem Text="Help" ImageUrl="/Images/question.png" Expanded="True">  
                <ItemTemplate> 
                    <uc1:ctrlQuestion ID="ctrlQuestion" runat="server" />
 
                </ItemTemplate> 
            </telerik:RadPanelItem> 
        </Items> 
</telerik:RadPanelBar> 

I want to access my control, but am not sure how to get at it:

...
RadPanelBar1.DataSource = objCollection;

RadPanelBar1.DataBind();

...

protected void RadPanelBar1_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)  
{  
     //?????
     ctrlQuestion.CallSomeMethod();           

I tried e.Item.FindControl("ctrlQuestion"), but it always returns null.

Any help would be greatly appreciated!

3 Answers, 1 is accepted

Sort by
0
Accepted
Paul
Telerik team
answered on 20 Aug 2009, 11:42 AM
Hi Charles,

Here's your modified code snippet that shows the needed approach.

protected void RadPanelBar1_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)   
{   
     Control uc = (Control)RadPanelBar1.FindItemByText("Help").FindControl("ctrlQuestion"); 
     uc.CallSomeMethod(); 
}  

Still, I think it will be too early to find the UserControl in the ItemDataBound event. You can try on panelbar's PreRender, i.e.

protected void RadPanelBar1_PreRender(object sender, EventArgs e) 
    { 
        Control uc = (Control)RadPanelBar1.FindItemByText("Help").FindControl("ctrlQuestion"); 
        uc.CallSomeMethod(); 
    } 


Regards,
Paul
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2009, 11:43 AM
Hi Charles,

Try the following code snippet in the PreRender event of the RadPanelbar and see whether you are able to access the UserControl from the ItemTemplate.

CS:
 
  protected void RadPanelBar1_PreRender(object sender, EventArgs e) 
    { 
        foreach (RadPanelItem panelItem in RadPanelBar1.Items) 
        { 
            WebUserControl userctl = (WebUserControl)panelItem.FindControl("ctrlQuestion"); 
            if (userctl != null
            { 
 
            } 
        } 
    } 

Note: Also set the AppendDataBoundItems property of the RadPanelBar to true.

Shinu
0
Charles Meyer
Top achievements
Rank 1
answered on 20 Aug 2009, 06:09 PM
Thank you everyone for the quick responses! Just to follow up for those who read this later, it turns out that this MUST be done on the PreRender event since ItemDataBound is too early in the page life cycle.
Tags
PanelBar
Asked by
Charles Meyer
Top achievements
Rank 1
Answers by
Paul
Telerik team
Shinu
Top achievements
Rank 2
Charles Meyer
Top achievements
Rank 1
Share this question
or