How to bind dropdown

D

David Smith

I want to use a combo box in a form that gets its data from another sql table
in the same database that the form is bound to. I want to view "States" and
insert the value "ST_ID".
 
T

Thomas A. Rowe

Is the form a HTML form with a .asp extensions or is the form a Access form? If the form is Access,
then you need to post to the Access newsgroup.

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================
 
D

David Smith

It is in an .aspx page that was put togather in FrontPage 2003. I found
validation code to add and got an e-mail function to work for me letting me
know when an order has been placed but I need a combo box to keep the state
that is entered to be correct. The database has a 1 to many relationship
beteen the state's abbreviation and the states names that I will be shipping
to. I want the combo box in the form "Orders" to receive info from a table
"States". I want the viewer to see the state's names but I want the
abbreviation to be inserted. I don't want a state that is not on the list.

If it was Access it would be easy(my openion only)

Thanks for your help!!

David Smith
 
D

David Berry

If this is an aspx page (ASP.NET) then you should try one of the .NET news
groups (microsoft.public.dotnet.*) since they would have more experts there
to help you code this in ASP.NET.
 
T

Thomas A. Rowe

Why not just create a drop down with just the supported states, i.e.:

<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================
 
D

David Berry

Tom,

That would be a good way for a normal HTML page but he said this was an aspx
(ASP.NET) page so that wouldn't be the most efficient way of doing it in
..NET. For example, you could do it this way:

<asp:DropDownList id="listState" runat="server"></asp:DropDownList>

Then you'd create a function to load the list. Ex:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' Check if page is loaded for the first time
If Not Page.IsPostBack Then
' Load the drop down list on the Page
LoadList()
End If
End Sub

Private Sub LoadList()

' Load the States Listbox
listState.Items.Add("Select your State")
listState.Items.Add(New ListItem("CA", "California"))
listState.Items.Add(New ListItem("CO", "Colorado"))
listState.Items.Add(New ListItem("CT", "Connecticut"))
listState.Items.Add(New ListItem("DE", "Delaware"))

... etc

listState.DataBind()
listState.SelectedIndex = 0
End Sub
 
T

Thomas A. Rowe

But if it is just a small list where would the saving be in running it from the server?

Even the 50 states is not a big list.
--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================
 
D

David Berry

I'm not saying you couldn't do it that way, just that It's just more
efficient to use the ASP.NET controls in a form. Otherwise why even bother
making it a .NET page. It's also easier to reference them later if you want
to do anything with inserting the values into a database.
 
T

Thomas A. Rowe

Ok.

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top