AjaxControlToolkit Accordion and databinding

删除回忆录丶 提交于 2020-01-06 04:45:30

问题


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

回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/1643368/ajaxcontroltoolkit-accordion-and-databinding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!