将多个文本框值存入数据库
我的表单中有多个文本框,例如 txtTask0、txtTask1...txtTask12。
所以我想将这些文本框的值一一传递到我的网络服务中。
for (int i = 0; i <= 12 ; i++)
{
sOUT = ws_service.InsertAchievement(i,txtTask0.Text,txtAchieve0.Text);
}
在这里,我不需要传递 txtTask0.text,而是需要一一传递“i”值,就像
txtTask[i].text
与此类似的
TextBox tb = (TextBox) Controls["txtTask" + i];
Error 92 The best overloaded method match for 'System.Web.UI.ControlCollection.this[int]' has some invalid arguments
如何将多个文本框值传递到循环中。?
I have multiple textboxes in my form like txtTask0, txtTask1... txtTask12.
so I want to pass values of those textboxes into my webservice one by one.
for (int i = 0; i <= 12 ; i++)
{
sOUT = ws_service.InsertAchievement(i,txtTask0.Text,txtAchieve0.Text);
}
Here instead of passing txtTask0.text I need to pass the "i" value one by one like
txtTask[i].text
something similar to this
TextBox tb = (TextBox) Controls["txtTask" + i];
from this link
But that code results in error like
Error 92 The best overloaded method match for 'System.Web.UI.ControlCollection.this[int]' has some invalid arguments
How can I pass multiple textbox values into the loop.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能这样做,因为 Controls[index] 需要一个整数作为其参数,但是你传递一个“与整数连接的字符串”,它不会工作,相反,你会像下面那样工作,希望它能帮助你。 ..
编辑:
如果条件
if(c is TextBox)
未正确解析,则执行编辑 2:
或者简单地,如果您想在 aspx 页面中的所有文本框控件中循环,请使用以下代码部分。它工作得非常完美..
You cant do like that, because the Controls[index] expects an integer as its parameter, but you are passing a "string concatenated with an integer" it wont work, instead you do like below it will work, hope it will help you...
EDIT :
If the condition
if(c is TextBox)
is not parsing correctly then do likeEDIT 2:
Or Simply if you want to loop out in all textbox controls in aspx page use this following code part. It works very perfectly..