如何在c#中的不同文本框中传输一系列项目 [英] How to Transfer a series of items in different textbox in c#
本文介绍了如何在c#中的不同文本框中传输一系列项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,其中一些项目按字符#分割。
例如:a#b#c#d#e输入textBox1
现在点击一个按钮,这些项目必须在其他文本框中输入。
eg
a in textBox2
b in textBox3
c in textBox4
d in textBox5
$ b $在textBox6
Plz帮助asap
谢谢
I have a textbox in which some items are splitted by character #.
eg: a#b#c#d#e are entered in textBox1
now by clicking a button these item must be entered in other textbox.
eg
a in textBox2
b in textBox3
c in textBox4
d in textBox5
e in textBox6
Plz help asap
Thanks
推荐答案
拆分TextBox
值并将其分配给其他TextBoxes
。
Split theTextBox
value and assign it to otherTextBoxes
.
string[] values = textBox1.Text.Split('#');
textBox2.Text = values[0];
textBox3.Text = values[1];
textBox4.Text = values[2];
textBox5.Text = values[3];
textBox6.Text = values[4];
为此您可以制作使用Split功能。下面是一个示例代码。
对于测试,我添加了一个文本框,我可以在其中输入数据,一个按钮和两个文本框,其中将填充数据。按下按钮后,您可以使用下面的代码填充。
For this you can make use of Split function available. Below is a sample code.
For testing i have added one textbox where i can enter data, a button and two textbox where data will be populated. After hitting button, you can use below code to populate.
protected void Button1_Click(object sender, EventArgs e)
{
string text = TextBox1.Text;
string [] text2 = text.Split('#');
int i = 1;
foreach (string item in text2)
{
if (i==1)
{
TextBox2.Text = item;
}
else if(i==2)
{
TextBox3.Text = item;
}
i++;
}
}
请标记为答案if它有帮助!!!
Please mark as answer if it helps!!!
这篇关于如何在c#中的不同文本框中传输一系列项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文