Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropdownList

Status
Not open for further replies.

masiwan

Vendor
Feb 20, 2006
37
UG
I'm new to ASP and I want to use VB.NET to satrt with, I'm creating creating a simple page on which I place a drop down list, containing three items, but when I try to run the application using Debug-> start without debugguing
the items just appera in text form and now in a list
what I'm I missing. I'm trying to follow a simple example from a book called:
visual basic.net database programming


 
Post your html code for the dropbox (see how it looks).
 
my code is this. the only line I add is:

"Response.Redirect(ddIURL.SelectedItem.Value)"

the rest is VB.net generated.
I have added three items on the list; setting their properties properly as explained in the book

I suspect there is something to do with configuration of Visual studio.net which I'm using . I'm using my Pc and I have installed IIS already

code:

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents ddIURL As System.Web.UI.WebControls.DropDownList

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub ddIURL_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddIURL.SelectedIndexChanged
Response.Redirect(ddIURL.SelectedItem.Value)

End Sub
End Class

 
The following is an incorrect QueryString:

Response.Redirect(ddIURL.SelectedItem.Value)

..it should look like..

Response.Redirect(mypage.aspx?myValue='" & ddIURL.SelectedItem.Value & "'")

In other words, the page in which you are redirecting to should be there, and the "Value" of the dropdown added as part of the QueryString.

Now if that was obvious and you are asking why does VS create such code I must admit I do not have a clue (I do all of my coding in Notepad).
 
In my project, I use a DropDownList to display the values. The value list is populated from a table. The list is over 1000 values. I can not type the part of the value and jump to the value in the list. There is also autopostback validation on the dropdownlist. I hope someone can give me some ideas how to type in part of the value to select the value in the long list without scroll down the list. Thanks, Jen
 
jen1701: I think I see what you are doing; that is; you have your correct URL string as a "value", for example, in your dropbox you have for value say "mypage.aspx", so that:

Response.Redirect(ddIURL.SelectedItem.Value)

..becomes..

Response.Redirect("mypage.aspx")

If you any problems with the string as URL you might alter the code such that it becomes something like:

Response.Redirect("'" & ddIURL.SelectedItem.Value & "'")

..to insure that it is a string; thought this may not be necessary.

There are examples if you are interested that would bring back say the first 100 values and then by clicking on an alphabetic link you can load the dropbox in groups of 100 at a time, this may save server resources. You might also turn off your Viewstate for this dropbox if you can (although AutoPostBack may intefer here) since it will be huge for 1,000 values. Of course, there are other considerations and alternatives.

With regards to typing in the first few letters there are some great references for autocomplete in dropdownlists ( Click here to see References)

Keep in mind as well jen that you can concatenate more than one field in the SQL as well as show more both Value and Text, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top