Selecting an item in a drop down list

Discussion in 'ASP .Net' started by Bogdan Zamfir, Aug 17, 2003.

  1. Hi,

    I have a page called MyTargetPage.aspx with a drop down list.
    When I pass control to that page, I send an ID in querystring, like this

    Server.transfer("MyTargetPage.aspx?PrjID=" & something)

    Then in page_load, after I populate the drop-down, I want to make default
    selection the item passed in query string
    So I use a code like this:

    dim MyID as string =Request.QueryString("PrjID")
    Dim lo As ListItem, i As Int16

    For i = 0 To cmbProject.Items.Count - 1

    If cmbProject.Items(i).Value = cProjectID Then

    Me.cmbProject.SelectedIndex = i

    End If

    Next

    This works, but doesn't seems to me to be a very elegant solution.
    Unfortunately I coudn't found a different one.

    Can anyone help with a better suggestion to accomplish this?



    Thank you

    Bogdan
     
    Bogdan Zamfir, Aug 17, 2003
    #1
    1. Advertising

  2. Bogdan Zamfir

    PJ Guest

    the SelectedValue property is read/write and assigning it will select the
    item w/ the corresponding value.

    cmbProject.SelectedValue = MyID

    "Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
    news:...
    > Hi,
    >
    > I have a page called MyTargetPage.aspx with a drop down list.
    > When I pass control to that page, I send an ID in querystring, like this
    >
    > Server.transfer("MyTargetPage.aspx?PrjID=" & something)
    >
    > Then in page_load, after I populate the drop-down, I want to make default
    > selection the item passed in query string
    > So I use a code like this:
    >
    > dim MyID as string =Request.QueryString("PrjID")
    > Dim lo As ListItem, i As Int16
    >
    > For i = 0 To cmbProject.Items.Count - 1
    >
    > If cmbProject.Items(i).Value = cProjectID Then
    >
    > Me.cmbProject.SelectedIndex = i
    >
    > End If
    >
    > Next
    >
    > This works, but doesn't seems to me to be a very elegant solution.
    > Unfortunately I coudn't found a different one.
    >
    > Can anyone help with a better suggestion to accomplish this?
    >
    >
    >
    > Thank you
    >
    > Bogdan
    >
    >
    >
    >
    >
     
    PJ, Aug 17, 2003
    #2
    1. Advertising

  3. Hi,

    > the SelectedValue property is read/write and assigning it will select the
    > item w/ the corresponding value.
    >
    > cmbProject.SelectedValue = MyID


    I don't know why, but DropDownlist doesn't seem to have this property. It
    doesn't shows up in Intellisense, and if I type it myself, I get a compile
    error.

    Are you sure are you talking about DropDownList?
    I found it as a property of ListBox only.

    Bogdan


    >
    > "Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
    > news:...
    > > Hi,
    > >
    > > I have a page called MyTargetPage.aspx with a drop down list.
    > > When I pass control to that page, I send an ID in querystring, like this
    > >
    > > Server.transfer("MyTargetPage.aspx?PrjID=" & something)
    > >
    > > Then in page_load, after I populate the drop-down, I want to make

    default
    > > selection the item passed in query string
    > > So I use a code like this:
    > >
    > > dim MyID as string =Request.QueryString("PrjID")
    > > Dim lo As ListItem, i As Int16
    > >
    > > For i = 0 To cmbProject.Items.Count - 1
    > >
    > > If cmbProject.Items(i).Value = cProjectID Then
    > >
    > > Me.cmbProject.SelectedIndex = i
    > >
    > > End If
    > >
    > > Next
    > >
    > > This works, but doesn't seems to me to be a very elegant solution.
    > > Unfortunately I coudn't found a different one.
    > >
    > > Can anyone help with a better suggestion to accomplish this?
    > >
    > >
    > >
    > > Thank you
    > >
    > > Bogdan
    > >
    > >
    > >
    > >
    > >

    >
    >
     
    Bogdan Zamfir, Aug 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Natty Gur
    Replies:
    1
    Views:
    323
    Bogdan Zamfir
    Aug 18, 2003
  2. KatMagic

    Selecting an item in a drop down list

    KatMagic, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    10,414
    KatMagic
    Apr 11, 2006
  3. Andrew
    Replies:
    2
    Views:
    512
    Jukka K. Korpela
    Apr 15, 2005
  4. weiwei
    Replies:
    0
    Views:
    1,040
    weiwei
    Jan 5, 2007
  5. Replies:
    5
    Views:
    288
Loading...

Share This Page