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,
TCIt 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:
Quote:
Originally Posted by
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
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
"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
news:1155449730.075705.116880@dotnet.itags.org.b28g2000cwb.googlegr oups.com...
Quote:
Originally Posted by
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:
Quote:
Originally Posted by
>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
>
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
TCook wrote:
Quote:
Originally Posted by
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
>
>
"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
news:1155449730.075705.116880@dotnet.itags.org.b28g2000cwb.googlegr oups.com...
Quote:
Originally Posted by
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:
Quote:
Originally Posted by
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
Hey Kumar,
I'm actually adding the 'option' list items via IE automation from the
clientside dynamically. When the page is submitted, I am checking for items
that are selected in the 'select' list. What's weird is that I'm also
populating text input controls using IE automation and their values show up
and are accessible. Below is the code that I use to create the 'option'
items:
For Each ThisItem In SomeItems
lstDropDown = docDocument.getElementById("MySelect")
optNewListItem = docDocument.createElement("option")
optNewListItem.innerText = ThisItem .Name
lstDropDown.appendChild(optNewListItem)
Next
Why aren't the 'select' controls working the same?
Regards,
Todd
"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
news:1155485796.567818.220730@dotnet.itags.org.m73g2000cwd.googlegr oups.com...
Quote:
Originally Posted by
>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
>
TCook wrote:
Quote:
Originally Posted by
>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
>>
>>
>"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
>news:1155449730.075705.116880@dotnet.itags.org.b28g2000cwb.googlegr oups.com...
Quote:
Originally Posted by
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
>
>
Hey Kumar,
Just for clarity, it's not that it's showing as not being selected but
rather as if it's empty (i.e. MySelectControl.Items.Count = 0)
Regards,
Todd
"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
news:1155485796.567818.220730@dotnet.itags.org.m73g2000cwd.googlegr oups.com...
Quote:
Originally Posted by
>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
>
TCook wrote:
Quote:
Originally Posted by
>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
>>
>>
>"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
>news:1155449730.075705.116880@dotnet.itags.org.b28g2000cwb.googlegr oups.com...
Quote:
Originally Posted by
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
>
>
I had never worked with IE automation, so I have no idea as how it
works with asp.net
TCook wrote:
Quote:
Originally Posted by
Hey Kumar,
>
Just for clarity, it's not that it's showing as not being selected but
rather as if it's empty (i.e. MySelectControl.Items.Count = 0)
>
Regards,
>
Todd
>
>
"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
news:1155485796.567818.220730@dotnet.itags.org.m73g2000cwd.googlegr oups.com...
Quote:
Originally Posted by
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
TCook wrote:
Quote:
Originally Posted by
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
>
>
"Kumar Reddi" <kumarreddi@dotnet.itags.org.gmail.comwrote in message
news:1155449730.075705.116880@dotnet.itags.org.b28g2000cwb.googlegr oups.com...
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
0 comments:
Post a Comment