开发者

AjaxControlToolkit Accordion and databinding

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>
</ContentTemplat开发者_开发问答e>

and in the c# code behind:

databoundaccordion.DataSource = presenter.getDataTable();
databoundaccordion.DataBind();


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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜