By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Dynamic variables in c#, how? possible?

P: 11
Ok, here's my dilemna. I have a web form that uses c# to process it. What I would like to do is create an array of the field names and then use that to reference the values of the fields.

so like if I had an array of {"name","phone","email"} I would like to loop them through something like

string temp = "";
foreach (string item in array)
temp = item.text;


where item.text would actually be "name.text" or "phone.text" as it loops through. In other web languages I'd have the ability to do something like eval(item+".text") or something like that to set temp to equal the value I am referring to. Does c# have a similar method?

This is a very simple view of what I am looking to do in the end.
Apr 24 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 692

Do you want to refer to the Controls on your Web Page?
If you want that, you can use controlCollection and loop through it.
Please refer this
Apr 24 '07 #2

P: 11
yes, that will work perfectly, thank you.
Apr 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.