C
crjunk
Hi everyone,
I'm trying to write a procedure in that will loop through all the
controls on a form. If the control is a DropDownList, then I want to
build a query based on the DropDownList's selected value. I'm not
very familiar with C#. I come from a VB.NET background.
Can someone tell me what I'm doing wrong ?
This is what I've tried to write:
DropDownList ctrlNameDropDown = new DropDownList();
foreach (Control ctrl in Page.FindControl("frmMain").Controls)
{
if (ctrl is DropDownList)
{
ctrlNameDropDown = (DropDownList)Page.FindControl(ctrl.ID);
// Write something to see if code is working.
Response.Write
(ctrlNameDropDown.SelectedItem.Text);
}
}
Thanks,
crjunk
I'm trying to write a procedure in that will loop through all the
controls on a form. If the control is a DropDownList, then I want to
build a query based on the DropDownList's selected value. I'm not
very familiar with C#. I come from a VB.NET background.
Can someone tell me what I'm doing wrong ?
This is what I've tried to write:
DropDownList ctrlNameDropDown = new DropDownList();
foreach (Control ctrl in Page.FindControl("frmMain").Controls)
{
if (ctrl is DropDownList)
{
ctrlNameDropDown = (DropDownList)Page.FindControl(ctrl.ID);
// Write something to see if code is working.
Response.Write
(ctrlNameDropDown.SelectedItem.Text);
}
}
Thanks,
crjunk