1
How can I simplify the code below using a loop, I’m in doubt depending on the name of Labels which 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();
What language? Explain this code better there.
– user28595
Friend, each language has its particularities. Please mention the language. This is basic in all questions. The more details, the better.
– Andrey
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero