Creating a DataTable with Dummy Data

I'm trying to bind a DataTable to an accordion, and I found that if I get a DataTable from a database using a table adapter, it fits perfectly to the accordion principle, but I want to create a dummy table (for testing if I don't have access to my database) The code for creating 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 bind data to this table, however, the accordion is not displayed. I can bind it to a gridview or detailview, but not to the accordion.

+5
source share
3 answers

4 , , DataSource .

:

DataSet ds = new DataSet();

        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("Branch");
        dt.Columns.Add("Officer");
        dt.Columns.Add("CustAcct");
        dt.Columns.Add("Grade");
        dt.Columns.Add("Rate");
        dt.Columns.Add("OrigBal");
        dt.Columns.Add("BookBal");
        dt.Columns.Add("Available");
        dt.Columns.Add("Effective");
        dt.Columns.Add("Maturity");
        dt.Columns.Add("Collateral");
        dt.Columns.Add("LoanSource");
        dt.Columns.Add("RBCCode");

        dt.Rows.Add(new object[] { "James Bond, LLC", 120, "Garrison Neely", "123 3428749020", 35, "6.000", "$24,590", "$13,432",
            "$12,659", "12/13/21", "1/30/27", 55, "ILS", "R"});

        ds.Tables.Add(dt);

        accReportData.DataSourceID = null;
        accReportData.DataSource = ds.Tables[0].DefaultView;
        accReportData.DataBind();

, . DataTable (dt), . dt.DefaultView . DataSet, . , . , , , , . Accordion.DataSource DataSet.Table.DefaultView .

+18

, 2.Columns.Add(...)

+1

, :

fooobar.com/questions/1034947/...

You can bind the Accordion Control to a DataTableReader created from the original DataTable

accReportData.DataSource = new System.Data.DataTableReader(ds.Tables[0]);
accReportData.DataBind();
0
source