Hasan Shouman
Hasan Shouman

Reputation: 2362

How to create dynamic RDLC data table

enter image description hereenter image description hereenter image description hereI need to pass to RDLC (SQL Server Reporting Services) report a data table with only one known column and all other columns are created at run time. That is I have column A that is know at design time, but before loading the report i will read values from the database and set these values as columns, may be i have one column and may be much more.

I tried this :

dsStatementOfAccount.DtEndDayDataTable dtMat = new dsStatementOfAccount.DtEndDayDataTable();

        dtMat.Columns.Add("c1");
        dtMat.Columns.Add("c2");

        DataRow row1 = dtMat.NewRow ();
        row1["Name"] = "Value for column name in row 1";
        row1["c1"] = "a";
        row1["c2"] = "a121"[1]

        dtMat.Rows.Add(row1);

        DataRow row2 = dtMat.NewRow();
        row2["Name"] = "Value for column name in row 2";
        row2["c1"] = "bbb";
        row2["c2"] = "bbb";

        dtMat.Rows.Add(row2);

But the report was loaded as the attached image .. How it can be done ?

Thanks

Upvotes: 1

Views: 3941

Answers (1)

Michael
Michael

Reputation: 1596

You should be able to do this by creating a column group that is grouped by your "NAME" column.

After adding your table to your report, define all static columns. Then, right-click on the cell where you want the dynamic columns to start at and select "Add Group > Parent Group (Under the column group section)" and choose to Group By "NAME". This should produce the desired effect.

EDIT: Attached picture of what it would look like in VS. Demonstration of column grouping.

Upvotes: 1

Related Questions