Question

I'm using the HeaderTemplate and the ContentTemplate of the Accordion control and binding it to a datatable. For some reason it doesn't display any data. If I bind the datatable to a datalist it works as ecpected, is this a known issue or am i doing something completely wrong. I'm binding the accordion control in the code behind if this makes any difference. Here is the code:

<cc1:Accordion ID="databoundaccordion" runat="server" AutoSize="None"  
HeaderCssClass="articleHeader" HeaderSelectedCssClass="articleHeaderSelected" 
ContentCssClass="articleBody" FadeTransitions="true" 
SuppressHeaderPostbacks="true" RequireOpenedPane="true" 
TransitionDuration="250" FramesPerSecond="40">
<HeaderTemplate>
    <%# DataBinder.Eval(Container.DataItem, "name")%>
</HeaderTemplate>
<ContentTemplate>
    <p>Content goes here</p>
    <a href="Articles.aspx">Go</a>
</ContentTemplate>

and in the c# code behind:

databoundaccordion.DataSource = presenter.getDataTable();
databoundaccordion.DataBind();
Was it helpful?

Solution

You will have difficulties binding an Accordion to a DataTable object.
Instead, do the following by converting it into a DataTableReader and it should work just fine:

databoundaccordion.DataSource
                    = new System.Data.DataTableReader(presenter.getDataTable());
databoundaccordion.DataBind();

Here's another example with sample data:

DataTable dt = new DataTable();
dt.Columns.Add("HeaderText");
dt.Columns.Add("ContentText");

dt.Rows.Add(new object[] { "Heading 1", "Content 1" });
dt.Rows.Add(new object[] { "Heading 2", "Content 2" });

databoundaccordion.DataSource = new System.Data.DataTableReader(dt);
databoundaccordion.DataBind();

OTHER TIPS

I have just built a simple example which works fine.

rather than using Databinder.Eval(Container.Item, "name") I used Eval("name")

this seems to work with the simple example, I will update when I've tested with my working code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top