<
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
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.
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
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.
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