使用字符串作为代码的一部分 [英] use a string as portion of code

查看:84
本文介绍了使用字符串作为代码的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for(int i = 0; i< NumberofPsgr; i ++)

{

if(field.GetAttribute(id)。Equals(addPassengerForm: psdetail:+ i +:psgnName))

{

field.SetAttribute(value,myform.PsgnName1.Text);

}

}







我有4个四个文本框PsgnName1,PsgName2,PsgnName3,PsgnName4。因为我通过循环来改变Html元素名称以填充文本框值我想要对文本框名称做同样的事情,例如



field.SetAttribute(value,myform.PsgnName+ i.toString()。Text);

但这会将文本框名称转换为字符串

解决方案

尝试使用示例中的方法此处。并尝试为您的按钮设置一些有意义的ID。然后你可以利用上述方法使用该ID获取它们。



PS:你可以使用一些LINQ / lambda表达式使方法更现代化。

for (int i = 0; i < NumberofPsgr; i++)
{
if (field.GetAttribute("id").Equals("addPassengerForm:psdetail:" + i + ":psgnName"))
{
field.SetAttribute("value",myform.PsgnName1.Text);
}
}



I have 4 four Text Boxes PsgnName1,PsgName2,PsgnName3,PsgnName4.Just as i vary Html element name to filled by a text box value by looping i want to do the same with textbox names something like

field.SetAttribute("value","myform.PsgnName" + i.toString().Text);
but this converts the textbox name to string

解决方案

Try to use the method from the example here. And try to set some meaningful IDs to your buttons. You can then get them using that ID leveraging the mentioned method.

PS: You may make the method a bit more modern using some LINQ/lambda expression stuff.


这篇关于使用字符串作为代码的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆