Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2004, 06:28 PM
Authorized User
 
Join Date: Jun 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to put dropdown values into another dropdown

Hi,

I've hit a bit of a block, can't figure out how to code around this in a decent way, but there must be a way to do it as it seems like a common enough need.

I have a dropdown box at the top of my ASP.NET page, it's populated with the values of a simple query that returns a customer code, a project number and a project name.

When the user selects the project they want to change in the dropdown and hit the 'Edit Project' button, I want to populate another dropdown box below that has a list of customers, and start on the customer code that they've selected. Then the second box below would have a project name, and would be filled in with the project name. Both of these lower boxes are data they could modify, effectively assigning a project a new customer code or a new name.

What I can't figure out is how to do the customer select dropdown box. If I have to put the code in the page to bind the list of customers before I know which project they select, how can I select the right customer code after they hit the button?

Hopefully that makes sense, my ASP.NET is getting a lot better but this seems like more of a logic problem almost.

Pat
 
Old November 11th, 2004, 10:41 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In your page code, the code for the "edit project" button will call the query to fill the client list based on the project that is selected in the project dropdown box. You don't need to populate the client list data (and in fact can't as you've pointed out) until you have a selection for the project.

Put the code necessary to populate the client list and whatever other controls you need to change in the button click event handler method.
 
Old November 12th, 2004, 01:59 AM
Authorized User
 
Join Date: Jun 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks planoie. If I insert the client dropdown (the one that gets filled after the project is selected) how can I code it though so that it shows up? For instance, if I put the dropdown in my code to begin with, it will be there before my button click has happened, don't I have to fill it before the button click and then somehow add something dynamic to change to the correct value in the client dropdown...

I tried it with inserting it all into a string (the code for the dropdown, the bind to a SQL datareader) but if that inserts at a label point after the button click, it's just text, not a server-side dropdown.

I feel like I'm missing something easy here..

Pat
 
Old November 12th, 2004, 09:52 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You something to this affect:

Markup
--------------------------------------------------------
<asp:dropdownlist runat="server" id="ddlProjects" />

<asp:button runat="server" id="cmdEditProject" text="Edit Project" onClick="cmdEditProject_OnClick" />

<asp:dropdownlist runat="server" id="ddlClients" visible="false" />


Server Code
--------------------------------------------------------
Sub cmdEditProject_OnClick (sender as Object, e as system.eventargs)
    ddlClients.Visible= true
    ddlClients.DataSource = GetClientList(ddlProjects.SelectedValue)
    ddlClients.DataBind()
End Sub

Function GetClientList(strProjectID) As DataTable
    'TODO: Get client list from database, return as datatable
End Function


Each time you click on the edit projects button, you'll repopulate the clients list.

Hope this will help get you started.
 
Old November 12th, 2004, 01:53 PM
Authorized User
 
Join Date: Jun 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! That was enough to get me going alright... got the page working exactly as I wanted it to!

Pat





Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox values to dropdown december Classic ASP Professional 1 July 3rd, 2006 08:34 PM
Get The Values In The DropDown vivek_inos Access VBA 1 November 30th, 2005 04:17 PM
Get The Values In The DropDown vivek_inos Access 2 November 30th, 2005 09:45 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM
Dropdown values dotnewnewbie ASP.NET 1.0 and 1.1 Professional 5 October 28th, 2003 12:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.