在asp.net中的文本框中循环并填充字符串数组
这是我的密码在asp.net中的文本框中循环并填充字符串数组,asp.net,vb.net,Asp.net,Vb.net,这是我的密码 Dim str As String = "str1,str2" Dim array() As String = str.Split(",") Dim MyListOfTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3} For index = 0 To array.Count - 1 For i = 0 To MyListOfTextBoxes.Length - 1
Dim str As String = "str1,str2"
Dim array() As String = str.Split(",")
Dim MyListOfTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3}
For index = 0 To array.Count - 1
For i = 0 To MyListOfTextBoxes.Length - 1
MyListOfTextBoxes(i).Text = array(index)
Next
Next
我有5个文本框。我只想用数组值填充textbox1和textbox2。因为不,我得说。但是,当我在
textbox1
、textbox2
和textbox3
上运行代码时,“str1”重复,这是因为您的代码通过元素0、1和2运行,这些元素对应于textbox1、textbox2和textbox3。如果只想填充TextBox1和TextBox2,请从阵列中删除TextBox3
你在另一个循环中也有一个循环-我不明白你为什么要这样做。你需要一个循环来完成它
Dim str As String = "str1,str2"
Dim array() As String = str.Split(",")
Dim MyListOfTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3}
For index = 0 To array.Count - 1
if(MyListOfTextBoxes.Length>index)
MyListOfTextBoxes(index).Text = array(index)
Next
但是我需要textbox3,因为我的str可能有3个单词,文本框必须填充。使用
将index=0填充到数组中。Count-1
我将数组值放入文本框中。谢谢你的回答。MyListoftExtboxs(index)
是正确的。你真的不应该硬编码文本框名称。当表单更改时会发生什么?您是否添加/删除了一个文本框?