Looping to find dynamic control values c#

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Can someone help me figure this out...

I've created dropdown boxes dynamically and added them to a panel on my
page.

how do i get the selectedvalue of the dropdownlist from the panel when i
click the submit button?

I've tryed :
pnlName.Controls[0]
to see if that would find the dropdownlist control but says:
Specified argument was out of the range of valid values. Parameter name:
index

Thanks in advance
Mike
 
Could you post the code that causes this failure? I suspect you havent
added it to the controls collection of the panel
Can someone help me figure this out...

I've created dropdown boxes dynamically and added them to a panel on my
page.

how do i get the selectedvalue of the dropdownlist from the panel when i
click the submit button?

I've tryed :
pnlName.Controls[0]
to see if that would find the dropdownlist control but says:
Specified argument was out of the range of valid values. Parameter name:
index

Thanks in advance
Mike
 
I figured it out with a foreach loop as follows:

foreach(Control ctrl in pnlOptionDdl.Controls)

{

DropDownList ddl = ctrl as DropDownList;

if(ddl!=null){

HttpContext.Current.Response.Write(ddl.SelectedItem.Text.ToString());

}

}



Thanks though :)



Dilip Krishnan said:
Could you post the code that causes this failure? I suspect you havent
added it to the controls collection of the panel
Can someone help me figure this out...

I've created dropdown boxes dynamically and added them to a panel on my
page.

how do i get the selectedvalue of the dropdownlist from the panel when i
click the submit button?

I've tryed :
pnlName.Controls[0]
to see if that would find the dropdownlist control but says:
Specified argument was out of the range of valid values. Parameter name:
index

Thanks in advance
Mike

--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
 
Back
Top