Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Selecting an item in a drop down list

Reply
Thread Tools

Selecting an item in a drop down list

 
 
Bogdan Zamfir
Guest
Posts: n/a
 
      08-17-2003
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





 
Reply With Quote
 
 
 
 
PJ
Guest
Posts: n/a
 
      08-17-2003
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:(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Bogdan Zamfir
Guest
Posts: n/a
 
      08-17-2003
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:(E-Mail Removed)...
> > 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
> >
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrive preselected value in second drop down list from the first drop down list weiwei ASP .Net 0 01-05-2007 07:29 PM
Selecting an item in a drop down list KatMagic ASP .Net 3 04-11-2006 07:25 PM
Auto Drop down a Drop Down List xxbmichae1@supergambler.com Javascript 5 11-23-2005 01:35 AM
Selecting Item in Drop Down List Box Andrew HTML 2 04-15-2005 04:46 PM
Re: Selecting an item in a drop down list Natty Gur ASP .Net 1 08-18-2003 02:40 PM



Advertisments