我在一个占位符中创建了一系列面板,每个面板内有5个文本框。
按下按钮时,我想从每个文本框中获取.Text以及面板的ID。我计划使用JaggedArray来跟踪所有面板及其内部TextBox。
string[][] jaggesaddress = new string[stop][]; //stop is an int and equal to amount of panels on screen.
String[] numbers = new String[stop];
int a = 0;
//Control ctrl;
foreach (Control ctrl in BookingPlaceholder.Controls) //BookingPlaceholder is placehodler ID
{
if (ctrl is Panel)
{
numbers[a] = ctrl.ID;
a++;
//ctrl.ID = numbers[a];
foreach(TextBox tb in ctrl.ID) // error here
{
}
}
}
但是,第二个foreach循环有一个错误,我不确定100%如何克服这个错误。
“无法将类型'char'转换为'System.Web.UI.WebControls.TextBox'”
我知道数字[a]确实找到了第一个面板,但是它是一个没有ID扩展名的字符串。
任何建议表示赞赏。
如果在PlaceHolder中有更多通用控件可用,则需要查找文本框控件。因此也可以安全地检查控件类型。
foreach (Control ctr in ctrl.Controls)
{
if (ctr is TextBox)
{
//Do your things
// ((TextBox)ctr).Text
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句