locked
Some question numbers don't show on the rdlc report RRS feed

  • Question

  • User-643157890 posted

    I need to print a 100-question test (stored into a datatable) to a Word document. Part 1-question 1 to question 56. Part2-question 57 to question 66;  Part3-question 67-question 100. Part 1 and Part 2 questions are required to be on two columns on paper. For example, questions appear on the  first page are following.
    1.                        7.
    2.                        8.
    3.                        9.
    4.                      10.
    5.                      11.
    6.                      12.

    I have created code behind and the report PT.rdlc. All questions are  showed up nicely on the Word doc except some of the question numbers are dropped off. I can't figure out why. Here are some my codes:

    int TRow = Dt.Rows.Count;  //TRow = number of rows in Part1 or Part2. Dt is a datatable that has 100 questions
    for (int RowCount = 0; RowCount < TRow; RowCount++)
    {
      TDt.Rows.Add(1);
      if (RowCount < TRow)
        TDt.Rows[TDt.Rows.Count - 1]["ID"] = Dt.Rows[RowCount]["qnum"]; //q1
      if RowCount + 6 < TRow
        TDt.Rows[TDt.Rows.Count - 1]["TID"] = Dt.Rows[RowCount + 6]["qnum"]; //q7
      ....
    }

    I do the same way above for all questions in Part 1 and 2. In the report, I use expressions as following for question numbers.

    =iif(Fields!question.Value<>"",Fields!ID.Value & ". ","") and
    =iif(Fields!Tquestion.Value<>"",Fields!TID.Value & ". ","")

    Can you please help me to identify what is wrong with some question numbers are dropped off? Thank you in advance.   

    Friday, February 12, 2016 7:30 PM

Answers

  • User-219423983 posted

    Hi newUser15,

    I have created a demo as below and you could have a look and it works on my client machine.

                DataTable Dt = new DataTable();
                Dt.Columns.Add("qnum", typeof(int));
                for (int i = 0; i < 12; i++)
                {
                    Dt.Rows.Add(i + 1);
                }
    
                DataTable TDt = new DataTable();
                TDt.Columns.Add("ID", typeof(int));
                TDt.Columns.Add("TID", typeof(int));
    
                int TRow = Dt.Rows.Count;  //TRow = number of rows in Part1 or Part2. Dt is a datatable that has 100 questions
                for (int RowCount = 0; RowCount < TRow; RowCount++)
                {
                    if (RowCount + 1 <= Math.Ceiling( TRow / 2.0))
                    {
                        TDt.Rows.Add(1);
                        TDt.Rows[TDt.Rows.Count - 1]["ID"] = Dt.Rows[RowCount]["qnum"]; //q1
                    }
                    else
                    {
                        TDt.Rows[RowCount - (int)Math.Ceiling(TRow / 2.0)]["TID"] = Dt.Rows[RowCount]["qnum"]; //q7
                    }
                }
    
                for (int i = 0; i < TDt.Rows.Count; i++)
                {
                    Console.WriteLine(TDt.Rows[i][0]+"-----"+ TDt.Rows[i][1]);
                }
    
                Console.Read();

    Best Regards,

    Albert Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 13, 2016 2:59 AM

All replies

  • User-219423983 posted

    Hi newUser15,

    I have created a demo as below and you could have a look and it works on my client machine.

                DataTable Dt = new DataTable();
                Dt.Columns.Add("qnum", typeof(int));
                for (int i = 0; i < 12; i++)
                {
                    Dt.Rows.Add(i + 1);
                }
    
                DataTable TDt = new DataTable();
                TDt.Columns.Add("ID", typeof(int));
                TDt.Columns.Add("TID", typeof(int));
    
                int TRow = Dt.Rows.Count;  //TRow = number of rows in Part1 or Part2. Dt is a datatable that has 100 questions
                for (int RowCount = 0; RowCount < TRow; RowCount++)
                {
                    if (RowCount + 1 <= Math.Ceiling( TRow / 2.0))
                    {
                        TDt.Rows.Add(1);
                        TDt.Rows[TDt.Rows.Count - 1]["ID"] = Dt.Rows[RowCount]["qnum"]; //q1
                    }
                    else
                    {
                        TDt.Rows[RowCount - (int)Math.Ceiling(TRow / 2.0)]["TID"] = Dt.Rows[RowCount]["qnum"]; //q7
                    }
                }
    
                for (int i = 0; i < TDt.Rows.Count; i++)
                {
                    Console.WriteLine(TDt.Rows[i][0]+"-----"+ TDt.Rows[i][1]);
                }
    
                Console.Read();

    Best Regards,

    Albert Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 13, 2016 2:59 AM
  • User-643157890 posted

    Hi Weibo,

    Thank you for spending time trouble shoot the codes.  I will check it and let you know.

    Monday, February 15, 2016 1:19 PM
  • User-219423983 posted

    Hi newUser15,

    Thank you for spending time trouble shoot the codes.  I will check it and let you know.

    Does my reply could help solve your issues? If it's helpful to you, you could mark it as answer to close this thread. If not, could you let me know what's wrong with my code so that I could modify my code to help you solve your issue?

    Best Regards,

    Albert Zhang

    Wednesday, February 24, 2016 11:48 AM
  • User-643157890 posted

    Yes, it does help. Thank you!

    Thursday, February 25, 2016 12:41 AM