I am trying to databind a DataTable to an accordion and I have found that If I retrieve the DataTable from a database using a table adapter it binds to the accordion perfectly however what I want to do is create a dummy table (for testing purposes if I don't have access to my database) the code to create the dummy table is below:
DataTable table2 = new DataTable("articletable");
table2.Columns.Add("articleID");
table2.Columns.Add("title");
table2.Columns.Add("content");
DataRow row = table2.NewRow();
row[0] = "1";
row[1] = "article name";
row[2] = "article contents go here";
table2.Rows.Add(row);
When I try to data bind that table however the accordion does not display. I can bind it to a gridview or detailsview but not the accordion.
Also, as seen in the answer below:
https://stackoverflow.com/a/6108163/637903
You can bind the Accordion Control to a DataTableReader constructed from the original DataTable
Make sure you specify a type for the columns in the table2.Columns.Add(...)
After 4 hours of banging my head against the wall, I discovered that the DataSource field is VERY picky.
Here's my code:
Turns out that the accordion only likes being bound to a dataset table's defaultview. I tried binding to just a DataTable (dt) and it failed. Even dt.DefaultView failed. Once I added it to a DataSet, it binds like a champ. Very annoying, with lost of wasted time. I know you've probably long-since forgotten this, but I wanted to make it available to future searchers. Accordion.DataSource must be bound to a DataSet.Table.DefaultView to work.