how to synchronize multiple drop down lists?

E

Ed Dror

Hi there
ASP.NET 2.0 VB & SQL Express

Lest take Northwind Categories Products as example

I create a table that hold these two together
and I create a stored procedure like
select ProductID, ProductName, CategoryID, from tblCategoryProducts
Where (CategoryID = @CategoryID)

and (in asp.net page) the where control I set to cboCategory.CategoryID

every thing works fine for the first time when you choose category it will
populate correctly the cboProducts
But it stuck on the first attempt when you chosse another category it won't
change the cboProducts

My question is how synchronize the Products CBO base on Caregory cbo on real
time changes
P.S it works fine with MS Access northwind database

Thanks,
Ed Dror
Andrew Lauren
 
W

Walter Wang [MSFT]

Hi Andrew,

After reading throught your post, I'm not quite clear on some points. Would
you please help me on these points:
1) Are you using ASP.NET Data Source controls such as ObjectDataSource or
SqlDataSource?
2) Would you please post some code such as how you associate the two
DropDownList? A complete working project is better, though.

If you are using Data Source controls, they can bind some parameter to a
control's property; thus when the control's property is changed on
postback, the Data Source control will automatically get updated data. Then
you bind your second DropDownList to the Data Source control.

I'm looking forward to your update so that we can continue further
discussion. Thank you.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Ed Dror

Walter,

I'm using sqlDataSource

Base on MS Dynamics SL I extracted the Modules (75) and Screens (1300)
Then I create one (Module) to Many (Screens) relationship
Then I create a table ModulesScreens looks like this

ModuleID, ModuleCode, ModuleName, ScreenID, ScreenName, ScreenNumber,
ScreenType

Now in WebDev Express asp.net I created one Drop Down list base on
sqlDatasource Modules tabls
Object Name = ModuleName + enable auto post back

Then I created Drop Down list base on Stored Procedure look like this
Object Name = ScreenNumber
set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[usp_SelectScreen]

@ModuleName varchar(50)

AS

SELECT ModuleName, ScreenName, ScreenNumber, ScreenType, ScreenID

FROM ScreensModules WHERE (ModuleName = @ModuleName)

ORDER BY ScreenName

With the WHERE = Control
ControlID = ModuleName (this is the Modules drop down list)
Value = ModuleName.SelectedValue

When you run this page it working for the first open drop down list

I'm picking General Ledger from Modules drop down and the second module show
all the screens
That belong to this module but when I pick another module name the second
drop down did not refresh
It stuck with the first pick from the drop down
Its very very similar to MS KB #289670 with Access database

I hope you will get the picture now and tell me how can I refresh the second
drop down list?

I also created a function that will call the stored procedure with passing
parameter from the Module drop down list
And (function call mySelectScreen)
Protected Sub ScreenName_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ScreenName.SelectedIndexChanged

Call mySelectScreen()

End Sub

but with no succsess

Thanks,

Ed
 
W

Walter Wang [MSFT]

Hi Ed,

Here're some steps I'm using to test the functionality:
1) Create a table Modules:

create table Modules(ModuleName varchar(50) not null)

2) Create a table ModuleScreens:

create table ModuleScreens(ModuleName varchar(50) not null, ScreenName
varchar(50) not null)

3) Insert some test data:

insert into Modules values('module1')
insert into Modules values('module2')
insert into ModuleScreens values('module1', 'screen1')
insert into ModuleScreens values('module2', 'screen2')

4) Create the stored procedure:

create procedure spGetScreenByModuleName
@ModuleName varchar(50)
as
select ScreenName from ModuleScreens
where ModuleName=@ModuleName

5) In web application, create a new WebForm, add first DropDownList,
configure it to use SqlDataSource to use SQL:

select ModuleName from Modules

and configure its Text and Value both to use the ModuleName field. Also
set its AutoPostBack = true.

6) Add another DropDownList, configure it to use a new SqlDataSource which
is configured to use the stored procedure; configure its parameter to use
control parameter and use first DropDownList's SelectedValue.

7) Run this WebForm, change selection of first DropDownList, you will see
the second DropDownList's values changes accordingly.

I hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
O

Oded Dror

Walter,

I did all that and it change but only for the first time
Like when you choose General Ledger module you will see the
Screen name drop down list with the general Ledger screens - ok

Now if you change the Module again like AR the ScreenName dropdown don't
change
It stay with the first time
All I want to change it all the time when you switch modules the screens
names will change too
How to make it like Refresh or Require like ms access without refreshing all
the page or
something when module text change then something happened

Ed,
 
W

Walter Wang [MSFT]

Hi Ed,

I understand that in your project it doesn't work as expected. Since I
don't have your project at hand, I had to use a simpler test project to
test the issue.

As I described in my last reply, the simple test works correctly. Would you
please try the steps in my last reply and see if it works or not?

If the simple test works, maybe you can compare it with your current
project and see which difference is causing the problem.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Ed Dror

Walter,

I did exactly what you have told me to do
Yes it works for the first time only
When I go back to the Module dropdown list and change it
The screen dropdown remain the same nothing change (it contain the first
module screen names)

Do you have a client side script that will reset the second dropdown list?
Because ASP.NET is the server side not a client side it won't change
We need to built a DLL to do this job?
Thanks,
Ed Dror
 
W

Walter Wang [MSFT]

Hi Ed,

Sorry for misunderstanding your previous reply. So let's do a summary so
far:

======
Using the simplest scenario as I described in my reply, when you click the
first DropDownList to select second item, the second DropDownList doesn't
show "screen2", right?
======

This is strange. Please help me on following questions so that we can go
further:
1) Is the WebForm actually performing a postback when you change the
selected item in first DropDownList? Since we've set its AutoPostBack=true,
it should.
2) Is javascript enabled in your web browser? Javascript is required to do
the postback correctly.

Also, would you please handle the second SqlDataSource's Selecting event by:

protected void SqlDataSource2_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
Response.Write(e.Command.Parameters[0].Value);
}

This will output the actual parameter value passed to the stored procedure.
When you change the first DropDownList's selected item, it should correctly
output the value.

Also, I've including my page source here for your reference:


======
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTE5NjE4MzgxODYPZBYCAgMPZBYGAgEPEA8WAh4LXyFEYXRhQm91bmRnZBAVA
gdtb2R1bGUxB21vZHVsZTIVAgdtb2R1bGUxB21vZHVsZTIUKwMCZ2dkZAIEDxAPFgIfAGdkEBUBB
3NjcmVlbjIVAQdzY3JlZW4yFCsDAWdkZAIFDw9kDxAWAWYWARYCHg5QYXJhbWV0ZXJWYWx1ZQUHb
W9kdWxlMhYBZmRkZKzAJI0cDOXzO1luqLJf1kXKgrvb" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<div>
<select name="DropDownList1"
onchange="javascript:setTimeout('__doPostBack(\'DropDownList1\',\'\')', 0)"
id="DropDownList1">
<option value="module1">module1</option>
<option selected="selected" value="module2">module2</option>

</select>
<select name="DropDownList2" id="DropDownList2">
<option value="screen2">screen2</option>

</select>

</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="/wEWBQLZ29nUDQKd5I/lCgKp3oX4AwL+mr84AtLI02u6LPTk2Ktx6jNq5AmDyvW71BVhr
A==" />
</div></form>
</body>
</html>
======

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Ed Dror

Walter,



Please take a look at Microsoft KB Article # 289670 How to synchronize two
combo boxes on a form in Access 2002/3

Let's take the Northwind database for example



All I want is to display two dropdown lists one for categories and one for
product

When user picks a category the products that belong to that category should
be display

When the user change category the product dropdown list must change also
based on category



And then submit this into a table

As of today we can't translate this article 289670 into ASP.NET 2.0



If you can show me how I will be very please (lets use the Northwind
database)



As of now I gave up on that I let the user's type instead of picking from
dropdown lists

Which eliminate typing errors?

(I have hundreds of users that using Microsoft Dynamics SL and it is very
time consuming)



Maybe Atlas will solved this issue



Thanks,



Ed Dror

Andrew Lauren



Walter Wang said:
Hi Ed,

Sorry for misunderstanding your previous reply. So let's do a summary so
far:

======
Using the simplest scenario as I described in my reply, when you click the
first DropDownList to select second item, the second DropDownList doesn't
show "screen2", right?
======

This is strange. Please help me on following questions so that we can go
further:
1) Is the WebForm actually performing a postback when you change the
selected item in first DropDownList? Since we've set its
AutoPostBack=true,
it should.
2) Is javascript enabled in your web browser? Javascript is required to do
the postback correctly.

Also, would you please handle the second SqlDataSource's Selecting event
by:

protected void SqlDataSource2_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
Response.Write(e.Command.Parameters[0].Value);
}

This will output the actual parameter value passed to the stored
procedure.
When you change the first DropDownList's selected item, it should
correctly
output the value.

Also, I've including my page source here for your reference:


======
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value=""
/>
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTE5NjE4MzgxODYPZBYCAgMPZBYGAgEPEA8WAh4LXyFEYXRhQm91bmRnZBAVA
gdtb2R1bGUxB21vZHVsZTIVAgdtb2R1bGUxB21vZHVsZTIUKwMCZ2dkZAIEDxAPFgIfAGdkEBUBB
3NjcmVlbjIVAQdzY3JlZW4yFCsDAWdkZAIFDw9kDxAWAWYWARYCHg5QYXJhbWV0ZXJWYWx1ZQUHb
W9kdWxlMhYBZmRkZKzAJI0cDOXzO1luqLJf1kXKgrvb" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<div>
<select name="DropDownList1"
onchange="javascript:setTimeout('__doPostBack(\'DropDownList1\',\'\')',
0)"
id="DropDownList1">
<option value="module1">module1</option>
<option selected="selected" value="module2">module2</option>

</select>
<select name="DropDownList2" id="DropDownList2">
<option value="screen2">screen2</option>

</select>

</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="/wEWBQLZ29nUDQKd5I/lCgKp3oX4AwL+mr84AtLI02u6LPTk2Ktx6jNq5AmDyvW71BVhr
A==" />
</div></form>
</body>
</html>
======

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
 

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