我的文本文件看起来像这样(10 x 10):
所以我想做的是,我想显示 100 个文本框,我使用用逗号分隔的字符串来检测要创建多少个文本框,假设为 100 个。但是当我尝试这样做时,它显示 110 个文本框,比平时多 10 个文本框。这里出了什么问题?
这是我的代码:
using (StreamReader reader = File.OpenText(Server.MapPath(@daoWordPuzzle.GetfileURL())))
{
string line = reader.ReadLine();
while ((line = reader.ReadLine()) != null)
{
// Response.Write(line + " <br />"); // Read every line in text file.
string[] lol = line.Split(new string[] { "," }, StringSplitOptions.None);
foreach (var value in lol)
{
int i = 0;
TextBox tb = new TextBox();
tb.MaxLength = (1);
tb.Width = Unit.Pixel(40);
tb.Height = Unit.Pixel(40);
tb.ID = i.ToString();
// Response.Write(value);
if (string.IsNullOrEmpty(value))
{
tb.Text = "";
// tb.Style["visibility"] = "hidden";
}
if (!string.IsNullOrEmpty(value))
{
tb.Text = "";
}
Panel1.Controls.Add(tb);
i++;
}
}
}