How can I simplify the code below using a loop, I am in doubt because of the names of the labels that are sequential, as I put something variable in FieldName1, NomeCampo2
, ..., NomeCampoX
.
lblNomeCampo1.Text = dt.Rows[1][0].ToString()+":";
lblCampo1.Text = dt.Rows[1][1].ToString();
lblNomeCampo2.Text = dt.Rows[2][0].ToString() + ":";
lblCampo2.Text = dt.Rows[2][1].ToString();
lblNomeCampo3.Text = dt.Rows[3][0].ToString() + ":";
lblCampo3.Text = dt.Rows[3][1].ToString();
lblNomeCampo4.Text = dt.Rows[4][0].ToString() + ":";
lblCampo4.Text = dt.Rows[4][1].ToString();
lblNomeCampo5.Text = dt.Rows[5][0].ToString() + ":";
lblCampo5.Text = dt.Rows[5][1].ToString();
lblNomeCampo6.Text = dt.Rows[6][0].ToString() + ":";
lblCampo6.Text = dt.Rows[6][1].ToString();
lblNomeCampo7.Text = dt.Rows[7][0].ToString() + ":";
lblCampo7.Text = dt.Rows[7][1].ToString();
lblNomeCampo8.Text = dt.Rows[8][0].ToString() + ":";
lblCampo8.Text = dt.Rows[8][1].ToString();
lblNomeCampo9.Text = dt.Rows[9][0].ToString() + ":";
lblCampo9.Text = dt.Rows[9][1].ToString();
lblNomeCampo10.Text = dt.Rows[10][0].ToString() + ":";
lblCampo10.Text = dt.Rows[10][1].ToString();