Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Indirect reference to controls or binding to arraylist i
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01341965
Message ID:
01342838
Views:
19
Hi Paul,

It's so close but I still can't get it to work. When I use ...GetValue(this), I get the error "Object reference not set to an instance of an object". I figured that was because the reference was to the form itself, rather than the control so I changed it to ...GetValue(txtName). I still get the error. I suspect it's still because it's reading the string rather than the reference to the control name, I just don't know what to do to get past that. I did make sure that the variable was indeed set to the name of a control on the form. Any ideas? Thanks.



>This is simplified so it's easier to see, but try something like this instead:
>
>
>for (int i = 1; i < 4; i++)
>{
>    string txtName = "textBox" + i.ToString();
>    TextBox control = (TextBox)this.GetType().GetField(txtName, MemberAccess).GetValue(this);
>
>    control.Text = i.ToString();
>}
>
Linda Harmes
HiBit Technologies, Inc.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform