I am guessing you have a HTML select control with runat=server. Even if
its not a HTML server control.. the only thing that stops the page from
remembering the items is the viewstate. If its the HTML server control,
see if the viewstate for the page is turned off. If the select control
is a asp.net webcontrol, see if the viewstate for the control or the
page is turned off..
Also, make sure you are loading the data into the control only once
during the page load.. but not during page postback also, which would
reset the control's items.. so, in that case the selected item value is
lost by the time you check its value in the button click event handler
Hey Kumar,
I'm actually trying the 'submit' button's 'Click' event and trying to use
VB.Net in the code behind class as follows:
For Each ThisItem In Me.MySelect.Items
If ThisItem.Selected = True Then
' Do something
End If
Next
I am able to read other controls this way but my 'select' control is
showing
as not having any items present even though there are when it is
displayed.
Any thoughts?
Todd
It should be quite simple to do the looping in javascript for a
"select" control..
You can do the looping with a simple for loop
for (i=0; i <= document.forms[0].SelectControlID.options.length - 1;
i++)
{
//do whatever...
}
TCook wrote:
Hello,
I was wondering if anyone has a code snippet for looping through a
'select'
control's 'option' elements?
Do I have to use an ASP.Net web control such as an asp list control or
dropdown to do such a thing?
Thanks,
TC