How: get dropdownlist value in a loop?

Results 1 to 2 of 2

Thread: How: get dropdownlist value in a loop?

  1. #1
    Join Date
    Dec 1969

    Default How: get dropdownlist value in a loop?

    Ok,<BR>I can get the value of a dropdownlist buy doing this: dropdownlist1.selecteditem.value, i have left the default id for all the dropdownlists i have on the page. What I am trying to do is get the value in a loop. here is a simple example of what i am trying to do and what.<BR><BR>dim temp as string<BR> for i=1 to 10 <BR> temp = dropdownlist(i).selecteditem.value<BR> next<BR><BR>Obviously that didn&#039;t work so i tryed <BR><BR>temp = dropdownlist"+cstr(i)+".selecteditem.value<BR><BR> that also is not working, can anyone help.<BR><BR>Thank you,<BR><BR>Santana

  2. #2
    Join Date
    Dec 1969

    Default I gather this is ASP.NET...

    ...and VB.NET, yes?<BR><BR>How about something like this:<BR><BR> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<BR> &#039; first get the form:<BR> Dim frm As Control = Me.FindControl("Form1")<BR> Dim i As Integer<BR> For i = 1 To 2 &#039; or whatever your range is<BR> Dim sel As DropDownList<BR> &#039; find the needed control by *name*<BR> sel = CType(frm.FindControl("DropDownList" & i), DropDownList)<BR> &#039; then do with it what you wish<BR> Response.Write(sel.ID & "=" & sel.SelectedIndex & "<BR>")<BR> Next<BR> End Sub<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts