使用一个文本框c#,asp.net构建数组
我需要建立一个表单,允许用户输入100个不同的测量值。然后输入100个不同的权重。我想使用相同的文本框。一个用于测量,一个用于重量。然后让他们存储该值,然后重置以接受下一个值,依此类推。有人能给我指出实现这一目标的正确方向吗?我找了一个多小时,什么也没找到。提前感谢您的帮助 当用户单击提交按钮时,将两个文本框的值添加到列表或字典中。执行此操作,直到达到所需的列表数。计数。如果我没有正确理解你的问题,请告诉我 在WPF(C#)中,它看起来像这样使用一个文本框c#,asp.net构建数组,c#,asp.net,C#,Asp.net,我需要建立一个表单,允许用户输入100个不同的测量值。然后输入100个不同的权重。我想使用相同的文本框。一个用于测量,一个用于重量。然后让他们存储该值,然后重置以接受下一个值,依此类推。有人能给我指出实现这一目标的正确方向吗?我找了一个多小时,什么也没找到。提前感谢您的帮助 当用户单击提交按钮时,将两个文本框的值添加到列表或字典中。执行此操作,直到达到所需的列表数。计数。如果我没有正确理解你的问题,请告诉我 在WPF(C#)中,它看起来像这样 //保存值的字典 Dictionary dict=新
//保存值的字典
Dictionary dict=新字典();
//方法,该方法在用户单击“提交”按钮时调用
私有void HandleSubmit(对象发送方、事件args args){
//将两个文本框的值添加到字典
dict.Add(textBox1.Text,Int32.Parse(textBox2.Text));
//检查是否输入了所有数据
//然后激活自定义方法
如果(dict.Count>=100){
自定义方法(dict);
}
}
--编辑--
@布里斯科维奇,我理解你的评论。首先要保存所有100个压力采样,然后输入100个重量采样。在这种情况下,不需要使用字典,您可以使用压力和重量两个列表。在这种情况下,代码将如下所示:
// Variables to save our data
// numberValues - number of values user needs to enter
// pressureList - list of entered pressure data
// weightList - list of entered weight data
int numberValues = 100;
List<int> pressureList = new List<int>();
List<int> weightList = new List<int>();
// Method that is called on user submit button click
// This method uses only one text box to input data,
// first we input pressure data until limit is reached
// and then weight data
private void HandleSubmit(object sender, EventArgs args) {
// Check if we are still entering pressure data, that
// is until we reach numberValues of pressure data values
// Same thing goes for weight list
if (pressureList.Count < numberValues) {
pressureList.Add(Int32.Parse(textBox1.Text));
}
else if (weightList.Count < numberValues) {
weightList.Add(Int32.Parse(textBox1.Text));
}
else {
// When we have #numberValues of values in both
// lists we can call custom method to process data
CUSTOMMETHOD(pressureList, weightList);
}
}
// Method for processing data
private void CUSTOMMETHOD(List<int> pressures, List<int> weights) {
// This loop will go through all values collected and
// will give you access to both pressure and weight on
// each iteration
for (int index = 0; index < numberValues; index++) {
int currentPressure = pressures.ElementAt(index);
int currentWeight = weights.ElementAt(index);
// Do processing here
}
}
//保存数据的变量
//numberValues-用户需要输入的值数
//压力列表-输入的压力数据列表
//weightList-输入的重量数据列表
int numberValues=100;
列表压力列表=新列表();
列表权重列表=新列表();
//方法,该方法在用户单击“提交”按钮时调用
//此方法仅使用一个文本框输入数据,
//首先,我们输入压力数据,直到达到极限
//然后是重量数据
私有void HandleSubmit(对象发送方、事件args args){
//检查我们是否仍在输入压力数据
//直到我们达到压力数据值的数值
//重量表也是如此
if(压力列表计数<数值){
Add(Int32.Parse(textBox1.Text));
}
else if(weightList.Count
当用户单击提交按钮时,将两个文本框的值添加到列表或字典中。执行此操作,直到达到所需的列表数。计数。如果我没有正确理解你的问题,请告诉我
在WPF(C#)中,它看起来像这样
//保存值的字典
Dictionary dict=新字典();
//方法,该方法在用户单击“提交”按钮时调用
私有void HandleSubmit(对象发送方、事件args args){
//将两个文本框的值添加到字典
dict.Add(textBox1.Text,Int32.Parse(textBox2.Text));
//检查是否输入了所有数据
//然后激活自定义方法
如果(dict.Count>=100){
自定义方法(dict);
}
}
--编辑--
@布里斯科维奇,我理解你的评论。首先要保存所有100个压力采样,然后输入100个重量采样。在这种情况下,不需要使用字典,您可以使用压力和重量两个列表。在这种情况下,代码将如下所示:
// Variables to save our data
// numberValues - number of values user needs to enter
// pressureList - list of entered pressure data
// weightList - list of entered weight data
int numberValues = 100;
List<int> pressureList = new List<int>();
List<int> weightList = new List<int>();
// Method that is called on user submit button click
// This method uses only one text box to input data,
// first we input pressure data until limit is reached
// and then weight data
private void HandleSubmit(object sender, EventArgs args) {
// Check if we are still entering pressure data, that
// is until we reach numberValues of pressure data values
// Same thing goes for weight list
if (pressureList.Count < numberValues) {
pressureList.Add(Int32.Parse(textBox1.Text));
}
else if (weightList.Count < numberValues) {
weightList.Add(Int32.Parse(textBox1.Text));
}
else {
// When we have #numberValues of values in both
// lists we can call custom method to process data
CUSTOMMETHOD(pressureList, weightList);
}
}
// Method for processing data
private void CUSTOMMETHOD(List<int> pressures, List<int> weights) {
// This loop will go through all values collected and
// will give you access to both pressure and weight on
// each iteration
for (int index = 0; index < numberValues; index++) {
int currentPressure = pressures.ElementAt(index);
int currentWeight = weights.ElementAt(index);
// Do processing here
}
}
//保存数据的变量
//numberValues-用户需要输入的值数
//压力列表-输入的压力数据列表
//weightList-输入的重量数据列表
int numberValues=100;
列表压力列表=新列表();
列表权重列表=新列表();
//方法,该方法在用户单击“提交”按钮时调用
//此方法仅使用一个文本框输入数据,
//首先,我们输入压力数据,直到达到极限
//然后是重量数据
私有void HandleSubmit(对象发送方、事件args args){
//检查我们是否仍在输入压力数据
//直到我们达到压力数据值的数值
//重量表也是如此
if(压力列表计数<数值){
Add(Int32.Parse(textBox1.Text));
}
else if(weightList.Count
与您所注意到的不同,此示例具有足够的通用性,因此它不是WPF特定的。此示例也适用于winforms甚至webforms。将在每个框中一次添加一个值。所以100个压力样本,然后是100个重量样本。那么我就可以从字典中提取这些值,并用其他方法处理它们了?@briskovich我添加了另一个更适合你的示例。这个示例非常通用,不像你提到的那样,它不是WPF特有的。此示例适用于winforms甚至更高版本