The DataTable's Rows show likw this, how do I fix it.

Month1 Month2 Month3
1
2
3
1
2
3
1
2
3

double C146_Calc = 0.0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // create the table
            DataSet ds = GetTable();
            outputView.DataSource = ds;
            outputView.DataBind();
        }
    }

    public DataSet GetTable()
    {
        double H30_Out = -63268973;
        double H91_Out = 5640000;
        double H94_Out = -846000;

        C146_Calc = H91_Out / 12;
        double C148_Calc = H94_Out / 12;

        double G158_In = 8;

        double C150_Out = C146_Calc + C148_Calc;

        DataTable dt = new DataTable("Details");
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);

        for (int i = 1; i <= 240; i++)
        {
            dt.Columns.Add("Month"+i, typeof(string));
        }

        DataRow dr3, dr4;

        DataRow dr = dt.NewRow();
        dr["Month1"] = String.Format("{0:#,###,###,###.##}", H30_Out);

        for (int i = 1; i <= 240; i++)
        {
            double num = 0.0;
            if (i == 13 || i == 25)
            {
                num = (C146_Calc * G158_In) / 100;
                
            }
            C146_Calc += num;

            DataRow row1 = dt.NewRow();
            row1["Month" + i] = String.Format("{0:#,###,###,###.##}", C146_Calc);
            DataRow row2 = dt.NewRow();
            row2["Month" + i] = String.Format("{0:#,###,###,###.##}", C148_Calc);
            DataRow row3 = dt.NewRow();
            row3["Month" + i] = String.Format("{0:#,###,###,###.##}", C150_Out);

            dt.Rows.Add(row1);
            dt.Rows.Add(row2);
            dt.Rows.Add(row3);
        }

        dt.Rows.Add(dr);
        return ds;
    }

Recommended Answers

All 9 Replies

Displays like this:

Month1 Month2 Month3
1
2
3
1
2
3
1
2
3

Cannot access the link.
Try inserting the image.

It an attachment.

OK, I copied your code and saw what you mean.
But if you study the code that is what you are doing.
You add 240 columns to the Details table - named Month1 to Month240.
You then add 720 rows to the table, three at a time.
To each of the three rows you only add data to one column.
What did you expect/hope to get?

I am hoping to get each months data, right underneath the heading column.

Then you only need three rows.
Move the DataRow row1 = dt.NewRow(); ( also row2 and row3) outside the for loop.

Oh, and put the

dt.Rows.Add(row1);
dt.Rows.Add(row2);
dt.Rows.Add(row3);

after it.

I see now, I was creating new rows for as long as the forloop ran.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.