本文介绍了如何循环数组并将值绑定到动态文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string Answer = objEvaluationQuestion.PossibleAnswers;
                string[] PossibleAnswer=Answer.ToString().Split(',');
                string a = "";

                for (int item=0; item < PossibleAnswer.Length;item++ )
                {
                    row = new TableRow();
                    cell = new TableCell();
                    TextBox tx = new TextBox();
                    tx.ID = "box" + item.ToString();
                    cell.Controls.Add(tx);
                    row.Cells.Add(cell);
                    table.Rows.Add(row);
                    //a..Add(table);
                    a = item + "," + a;
                }


                txtPossibleAnswers.Text = objEvaluationQuestion.PossibleAnswers;









这是我的代码

此时





this is my code
at this point

string[] PossibleAnswer=Answer.ToString().Split(',');



i得到的值为5(例如)




i got the value 5 (for example)

for (int item=0; item < PossibleAnswer.Length;item++ )
                {
                    row = new TableRow();
                    cell = new TableCell();
                    TextBox tx = new TextBox();
                    tx.ID = "box" + item.ToString();
                    cell.Controls.Add(tx);
                    row.Cells.Add(cell);
                    table.Rows.Add(row);
                    //a..Add(table);
                    a = item + "," + a;
                }





使用此循环我想动态创建文本框。



并显示我来这里的数据库的价值





using this loop i want to create the text boxes dynamically.

and show the value for my database which i am getting here

txtPossibleAnswers.Text = objEvaluationQuestion.PossibleAnswers;  





给我的用户。



帮我plz



to my user.

help me plz

推荐答案

for (int item=0; item < PossibleAnswer.Length;item++ )
{
    row = new TableRow();
    cell = new TableCell();
    TextBox tx = new TextBox();
    tx.ID = "box" + item.ToString();
    tx.Text = item.ToString();
    cell.Controls.Add(tx);
    row.Cells.Add(cell);
    table.Rows.Add(row);
    //a..Add(table);
    a = item + "," + a;
}





希望这会有所帮助。



问候

Jegan



Hope this helps.

Regards
Jegan


这篇关于如何循环数组并将值绑定到动态文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:14