Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 13-Feb-15 23:20pm
v2

1 solution

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.
 
Share this answer
 
v2
Comments
Rahul Anand Jha 14-Feb-15 8:11am    
It didnt work.Simply speaking i want to vary my variable names used for setting a value using a loop.For i=1 PsgnName(i) will represent TextBox PsgnName1 for i=2 it will represent TextBox PsgnName2 .I want to access PsgnName(i).Text.I tried adding a .Text but didnt help.
I dont want to insert this string here rather i want to insert the value of the text contained in TextBox myform.PsgnName(i)
Vladimir Svyatski 14-Feb-15 8:38am    
OK, I see what you mean. Try the updated solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900