guitarProgrammer
guitarProgrammer

Reputation: 31

Foreach row in Gridview print C#

I want each row of the gridview to print on the next line. This code just gets the same 3 lines over and over. What am I doing wrong?

foreach (GridViewRow row in poGridview.Rows) {
    String itemNum = poGridview.Rows[0].Cells[0].Text;        
    String house = poGridview.Rows[0].Cells[2].Text;
    String description = poGridview.Rows[0].Cells[1].Text;
    Paragraph itemLine1 = new Paragraph(@"" + itemNum + "         " + house + "          " + description, body);
    p.Add(itemLine1);   
}

Upvotes: 0

Views: 3464

Answers (1)

D Stanley
D Stanley

Reputation: 152566

You are referencing the same row (poGridview.Rows[0]) every time within the loop. Change the reference to row:

foreach (GridViewRow row in poGridview.Rows)
{
    String itemNum = row.Cells[0].Text;        
    String house = row.Cells[2].Text;
    String description = row.Cells[1].Text;
    Paragraph itemLine1 = new Paragraph(@"" + itemNum + "         " + house + "          " + description, body);
    p.Add(itemLine1);   
}

Upvotes: 2

Related Questions