Cascaded menus and multi-select CheckBoxList

D

dbuchanan

There are three parts to this



1.) How do I cascade menus?



2.) And, how do I cascade menus with a multi-select CheckBoxList?



3.) How do I default to all? When no items are selected. (I know how to
detect no box selected . I just don't know how to 'lose' the where statement
if no list box is selected.)



Here are the select statements;



The query for the first menu

select usr ,grpId

from tblgrp



The query for the second menu

select car, carId

from tblCars

where grpI in (@grpId)



Please answer questions 1, 2 and 3.



Thank you,

Doug
 
S

Steven Cheng [MSFT]

Hi Doug,

Regarding on the questionsa bout the Menu control, I'd like to confirm some
further things:

1)As for cascading the menu control, do you mean you want to display data
via Menu control and make menu items displayed in different layers? If so,
based on my research, the menu control does support multiple level
menuitems display. And so far there are several means to populate menu
items:

i. use code to programmtically populate the Menu control's Menu items
collection
ii. use databindings setting, and a very common approad is supply a xml
datasource which can map different xml element at different menu level.

#Populating Menu Control in ASP.NET 2.0 - using different data sources
http://www.codeproject.com/KB/menus/PopulatingMenuControlASP2.aspx

http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/ctrlref/naviga
tion/menu.aspx

Also, for your scenario, it quite depend on your datasource(what are the
original data structure) which will impact how we can associate it with the
menu control


2)And, how do I cascade menus with a multi-select CheckBoxList?
======================
I'm still a bit unclear about this, are you using checkboxlist inside menu
template or would you further clarity how you currrently integrated
checkboxlist with menu control?

3)How do I default to all? When no items are selected. (I know how to
detect no box selected . I just don't know how to 'lose' the where
statement
if no list box is selected.)
============================
for this question, I'm wondering how do you currently execute the select
statement, are you directly execute it via ADO.NET code or use a SQL
DataSource control?

*If using ADO.NET code, I think you can explicitly check whether there is
no item selected and change to use a non-where select statement for that
case.

*If you are using SqlDatasource control. One approach I can think is
putting two different data source control on page(one of them always return
all the records) and you can programmtically assign the proper one to the
Menu or databound control(depend on whether there is element selected).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
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.





--------------------
 
D

dbuchanan

Steven,

I am sorry, my choice of words was bad. Instead of *menu* I should have said
*control*.

What I am trying to do is have the first of two controls filter what is
displayed in the second control.

For example if in the first CheckBoxList (multi-select) the user selects
'NorthEast' and 'SouthWest' regions then the second CheckBoxList
(multi-select) will display 'Maine', 'New York', 'Nevada' and 'New Mexico'
but will not display 'Oregon' or 'Florida' becuase they are in the
'NorthWest' and 'SouthEast" which were not selected in the first
CheckBoxList.

1.) How do I have the first control supply the parameters for the second
control? I am looking for a good explaination because I am new to aspx. A
link to a very good walk-through - if it is good - would be nice.

Up to now I had set up my controls by using a SqlDataSource. This time I
tried to set my control by putting my queries in a tableAdapter insid my
XSD. While doing this I noticed functionality for setting up parameters. I
would guess thia is how I would set up one contro to be dependant upon
another.

BUT... ( and before setting up parameters)

I tried to run the project to see the controls populate. Instead it crashed
with the error below.

2.) What could I have done wrong?

Thank you,
Doug

=== starr of error ==============
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 931: this.Adapter.SelectCommand = this.CommandCollection[0];
Line 932: if ((this.ClearBeforeFill == true)) {
Line 933: dataTable.Clear();
Line 934: }
Line 935: int returnValue = this.Adapter.Fill(dataTable);


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\websiterlftirekingdomcoursecompletionreport\7697443b\2ec251ca\App_Code.9o1brfaa.0.cs
Line: 933

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
ControlsDataSetTableAdapters.CourseGroupsTableAdapter.FillSelectCourseGroups(CourseGroupsDataTable
dataTable) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET
Files\websiterlftirekingdomcoursecompletionreport\7697443b\2ec251ca\App_Code.9o1brfaa.0.cs:933

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
skipVisibilityChecks) +358
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod
method, Boolean disposeInstance, Object& instance) +676
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments
arguments) +2664
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +65
System.Web.UI.WebControls.ListControl.PerformSelect() +32
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92
System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
+33
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +31
System.Web.UI.WebControls.CheckBoxList.OnPreRender(EventArgs e) +38
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4436
 
S

Steven Cheng [MSFT]

Hi Doug,

If you're not quite familar with ASP.NET Data Access and DataBound control
model, I suggest you have a look at the Data Access tutorial on ASP.NET
official site:

#Data Access Tutorials
http://www.asp.net/learn/data-access/

the tutorial contains many very good and typical samples.

Also, for your scenario, since your second control's datasource(result set)
will rely on the first control(checkboxlist's selected items). I would
suggest you manually use code to check all the selected items in the first
CheckBoxList control e.g.

============
foreach (ListItem item in CheckBoxList1.Items)
{
if(item.Selected == true)
//append to query parameter
}
============

After that, you also programmtically use ADO.NET SqlCommand to execute
command and get the DataReader or DataSet and bind it to DataGrid/Gridview
control. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "dbuchanan" <[email protected]>
References: <[email protected]>
Subject: Re: Cascaded menus and multi-select CheckBoxList
Date: Thu, 5 Jun 2008 02:30:33 -0400
Steven,

I am sorry, my choice of words was bad. Instead of *menu* I should have said
*control*.

What I am trying to do is have the first of two controls filter what is
displayed in the second control.

For example if in the first CheckBoxList (multi-select) the user selects
'NorthEast' and 'SouthWest' regions then the second CheckBoxList
(multi-select) will display 'Maine', 'New York', 'Nevada' and 'New Mexico'
but will not display 'Oregon' or 'Florida' becuase they are in the
'NorthWest' and 'SouthEast" which were not selected in the first
CheckBoxList.

1.) How do I have the first control supply the parameters for the second
control? I am looking for a good explaination because I am new to aspx. A
link to a very good walk-through - if it is good - would be nice.

Up to now I had set up my controls by using a SqlDataSource. This time I
tried to set my control by putting my queries in a tableAdapter insid my
XSD. While doing this I noticed functionality for setting up parameters. I
would guess thia is how I would set up one contro to be dependant upon
another.

BUT... ( and before setting up parameters)

I tried to run the project to see the controls populate. Instead it crashed
with the error below.

2.) What could I have done wrong?

Thank you,
Doug

=== starr of error ==============
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 931: this.Adapter.SelectCommand = this.CommandCollection[0];
Line 932: if ((this.ClearBeforeFill == true)) {
Line 933: dataTable.Clear();
Line 934: }
Line 935: int returnValue = this.Adapter.Fill(dataTable);


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\websiterlftirekingdomcoursecompletionreport\7697443b\2ec251ca\App_Cod e.9o1brfaa.0.cs
Line: 933

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
ControlsDataSetTableAdapters.CourseGroupsTableAdapter.FillSelectCourseGroups
(CourseGroupsDataTable
dataTable) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET
Files\websiterlftirekingdomcoursecompletionreport\7697443b\2ec251ca\App_Cod e.9o1brfaa.0.cs:933

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
skipVisibilityChecks) +358
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSource
Method
method, Boolean disposeInstance, Object& instance) +676
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelec
tArguments
 
S

Steven Cheng [MSFT]

Hi Doug,

Have you got any progress or does my further suggetion help you some?

Please feel free to let me know if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: (e-mail address removed) (Steven Cheng [MSFT])
Organization: Microsoft
Date: Fri, 06 Jun 2008 07:28:22 GMT
Subject: Re: Cascaded menus and multi-select CheckBoxList
Hi Doug,

If you're not quite familar with ASP.NET Data Access and DataBound control
model, I suggest you have a look at the Data Access tutorial on ASP.NET
official site:

#Data Access Tutorials
http://www.asp.net/learn/data-access/

the tutorial contains many very good and typical samples.

Also, for your scenario, since your second control's datasource(result set)
will rely on the first control(checkboxlist's selected items). I would
suggest you manually use code to check all the selected items in the first
CheckBoxList control e.g.

============
foreach (ListItem item in CheckBoxList1.Items)
{
if(item.Selected == true)
//append to query parameter
}
============

After that, you also programmtically use ADO.NET SqlCommand to execute
command and get the DataReader or DataSet and bind it to DataGrid/Gridview
control. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "dbuchanan" <[email protected]>
References: <[email protected]>
Subject: Re: Cascaded menus and multi-select CheckBoxList
Date: Thu, 5 Jun 2008 02:30:33 -0400
Steven,

I am sorry, my choice of words was bad. Instead of *menu* I should have said
*control*.

What I am trying to do is have the first of two controls filter what is
displayed in the second control.

For example if in the first CheckBoxList (multi-select) the user selects
'NorthEast' and 'SouthWest' regions then the second CheckBoxList
(multi-select) will display 'Maine', 'New York', 'Nevada' and 'New Mexico'
but will not display 'Oregon' or 'Florida' becuase they are in the
'NorthWest' and 'SouthEast" which were not selected in the first
CheckBoxList.

1.) How do I have the first control supply the parameters for the second
control? I am looking for a good explaination because I am new to aspx. A
link to a very good walk-through - if it is good - would be nice.

Up to now I had set up my controls by using a SqlDataSource. This time I
tried to set my control by putting my queries in a tableAdapter insid my
XSD. While doing this I noticed functionality for setting up parameters. I
would guess thia is how I would set up one contro to be dependant upon
another.

BUT... ( and before setting up parameters)

I tried to run the project to see the controls populate. Instead it crashed
with the error below.

2.) What could I have done wrong?

Thank you,
Doug

=== starr of error ==============
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 931: this.Adapter.SelectCommand = this.CommandCollection[0];
Line 932: if ((this.ClearBeforeFill == true)) {
Line 933: dataTable.Clear();
Line 934: }
Line 935: int returnValue = this.Adapter.Fill(dataTable);


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\websiterlftirekingdomcoursecompletionreport\7697443b\2ec251ca\App_Co
d
e.9o1brfaa.0.cs
Line: 933

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
ControlsDataSetTableAdapters.CourseGroupsTableAdapter.FillSelectCourseGroup
s
(CourseGroupsDataTable
dataTable) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET
Files\websiterlftirekingdomcoursecompletionreport\7697443b\2ec251ca\App_Co
d
e.9o1brfaa.0.cs:933

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
skipVisibilityChecks) +358
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourc
e
Method
method, Boolean disposeInstance, Object& instance) +676
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSele
c
tArguments
arguments) +2664
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +65
System.Web.UI.WebControls.ListControl.PerformSelect() +32
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92
System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
+33
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +31
System.Web.UI.WebControls.CheckBoxList.OnPreRender(EventArgs e) +38
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4436




--------------------------------------------------------------------------
-
 
S

Steven Cheng [MSFT]

Thanks for your reply Doug,

I'm glad that the suggestion help you.

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

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

==================================================
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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top