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

How PanelBar ItemTemplate works?

4 Answers 178 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Edwin
Top achievements
Rank 1
Edwin asked on 08 Aug 2008, 08:04 AM

<

telerik:RadPanelBar ID="mnuCategory" runat="server" Skin="Hay" Width="200px" ExpandMode="SingleExpandedItem" PersistStateInCookie="true">
  <ItemTemplate>
  Some text
  </ItemTemplate>
</
telerik:RadPanelBar>

Code behind:

protected

void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
    mnuCategory.DataSource = MyBusinessRule.GetDataTable();
    //mnuCategory.DataFieldID = "Id";
    //mnuCategory.DataFieldParentID = "ParentId";
    //mnuCategory.DataTextField = "Name";
    //mnuCategory.DataValueField = "Id";
    //mnuCategory.DataNavigateUrlField = "PageUrl";
    mnuCategory.DataBind();
}
}

I expect the PanelBar shows "Some text" in all items but it just gave me System.Data.DataRowView.  If I uncomment the codes above, I can see a "normal" PanelBar but the ItemTemplate seems has no effect at all.

What have I done wrong?

PS:  The PanelBar is in a WebUserControl (ascx) if it does matter.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Aug 2008, 11:14 AM
Hello Edwin,

I tried this on my end and found that the text does appear below the bound data. I am not sure about your problem but one suggestion is to place a Label in the ItemTemplate and set its custom text as shown below.

aspx:
 <telerik:RadPanelBar ID="RadPanelBar1" runat="server" > 
        <ItemTemplate> 
            <asp:Label ID="Label1" runat="server" Text="Some Text" BackColor="Red" ForeColor="Black"></asp:Label> 
        </ItemTemplate>            
 </telerik:RadPanelBar> 

Thanks
Princy.
0
Sean
Top achievements
Rank 2
answered on 09 Aug 2008, 04:31 AM
The reason you see System.Data.DataRowView for each item is because you bound to a data object without identifying the dataField and DataText fields. That is why they appear when you uncomment your code.

If you want  a your text to appear in each panel bar generated, I would think you would have to do so in the ItemDataBound event somewhere. I have a project that does just that, because I hit the same wall you are hitting. I only wanted ONE top bar, with a databound set of sub-bar items. I did a foreach loop... the project will be getting submitted to the site soon, so maybe it will help.

Exactly what are you looking to do? Have a set template that falls under wach bound item? Princy, I didn't see the 'Some Text' anywhere, even with your suggested fix.

It is strange how different folks see it differently..:) Maybe browser differences?

Thanks for listening!

Sean
Electronic Arts, Orlando
0
Paul
Telerik team
answered on 11 Aug 2008, 12:16 PM
Hi there,

Here's a sample code snippet that shows the needed approach.

ASPX:
<form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server">  
        <ItemTemplate> 
            <asp:Label ID="Label1" runat="server" Text="Some Text" BackColor="Red" ForeColor="Black"></asp:Label> 
        </ItemTemplate> 
        <CollapseAnimation Duration="100" Type="None" /> 
        <ExpandAnimation Duration="100" Type="None" /> 
    </telerik:RadPanelBar> 
</form> 

Code-behind:
using System;  
using System.Data;  
using System.Configuration;  
using System.Collections;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
 
public partial class _Default : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!IsPostBack)  
        {  
            RadPanelBar1.DataSource = CreateTestTable();  
            //Establish hierarchy:  
            RadPanelBar1.DataFieldID = "ID";  
            RadPanelBar1.DataFieldParentID = "ParentID";  
            //Set Text, Value, and NavigateUrl:  
            RadPanelBar1.DataTextField = "Text";  
            RadPanelBar1.DataValueField = "ID";  
            RadPanelBar1.DataNavigateUrlField = "URL";  
            RadPanelBar1.DataBind();  
        }  
    }  
 
    private DataTable CreateTestTable()  
    {  
        DataTable table = new DataTable();  
        table.Columns.Add("ID");  
        table.Columns.Add("ParentID");  
        table.Columns.Add("Text");  
        table.Columns.Add("URL");  
        table.Columns.Add("Tooltip");  
        table.Rows.Add(new string[] { "1"null"root 1"null"root 1 tooltip" });  
        table.Rows.Add(new string[] { "2"null"root 2"null"root 1 tooltip" });  
        table.Rows.Add(new string[] { "3""1""child 1.1"null"child 1.1 tooltip" });  
        table.Rows.Add(new string[] { "4""1""child 1.2"null"child 1.2 tooltip" });  
        table.Rows.Add(new string[] { "5""1""child 1.3"null"child 1.3 tooltip" });  
        table.Rows.Add(new string[] { "6""5""child 1.3.1"null"child 1.3.1 tooltip" });  
        table.Rows.Add(new string[] { "7""5""child 1.3.2"null"child 1.3.2 tooltip" });  
        table.Rows.Add(new string[] { "8""5""child 1.3.3"null"child 1.3.3 tooltip" });  
        return table;  
    }   
}  
 


Sincerely yours,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Edwin
Top achievements
Rank 1
answered on 12 Aug 2008, 03:07 PM
Hi  Paul
I have tried your code and in each PanelItem I get the text and link and then "some text" underneath.  What I thought originally is that ItemTemplate allows me to have a complete control of what is being rendered inside the panel item.  However, it seems it is just an additonal part under the normal Panel Item.  Anyway, I can live with that even though I feel a bit disappointed about the usability of ItemTemplate in panelbar.
Regards
Edwin
Tags
PanelBar
Asked by
Edwin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sean
Top achievements
Rank 2
Paul
Telerik team
Edwin
Top achievements
Rank 1
Share this question
or