Is there a way in c# to create a string and use that as an object or control name? For example, if I had an object "listBox.foo", and 2 string variables "string string1 = "listBox"; string string2 = "foo";, is there anyway to build the object name from that so I could call a method like ${string1+"."+string2"}.Visible=false" Thanks for any pointers! I have looked at the FindControl function so I could do "mycontrol = FindControl(string1+string2); mycontrol.Visible=false". However, although I use System.Web.UI, the compiler still complains that it's not available in the context.
D
dug_r
@dug_r
Posts
-
Referencing object by substituing object name in c#? -
Get value from listbox itemszeeShan, I hope this helps. It depends on what you want to do with your items. They are usually cast at some point. Consider this code. When something is selected in listBox1, it copies all of the contents into listBox2: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { foreach (string item in listBox1.Items) { listBox2.Items.Add(item); } }