Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Determining item count of databound DropDownList

Reply
Thread Tools

Determining item count of databound DropDownList

 
 
Kyle K.
Guest
Posts: n/a
 
      06-08-2006
Environment: ASP.NET 2 on WinXP SP2 w/ VS2005

I have a Databound DropDownList control on a templated page that I would
like to conditionally display as determined by the # of items in the
control.

Using a MultiView control...
Count = 0, display a message (view1)
Count > 0, display DropDownList & Button (view2)

I need the ability to programatically set which view is displayed AFTER
the DropDownList has loaded the data from the database.

I tried placing the code to do this inside the Page_Load() &
(controlName)_DataBound() events, but the Page_Load() event is called
before the data is bound and the (controlName)_DataBound() event doesn't
get called at all (breakpoint not reached when debugging the page).

Not sure if it matters or not, but I am using an ObjectDataSource that
references a DataSet (.xsd).

What method should I use in order to determine which view is displayed
at runtime?

-={ Kyle K }=-
 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      06-08-2006
Hi Kyle,

1- you can get the count while handling the Selected event of the
objectDataSource. You may look at the code of this demo for an example:
http://www.webswapp.com/codesamples/...w/default.aspx

2- the reason your (controlName)_DataBound() event was not fired could be
that you have not wired the event handler to the event. For example, have
you added OnDataBound="controlName_DataBound" to the markup of the
dropdownlist?
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Kyle K." wrote:

> Environment: ASP.NET 2 on WinXP SP2 w/ VS2005
>
> I have a Databound DropDownList control on a templated page that I would
> like to conditionally display as determined by the # of items in the
> control.
>
> Using a MultiView control...
> Count = 0, display a message (view1)
> Count > 0, display DropDownList & Button (view2)
>
> I need the ability to programatically set which view is displayed AFTER
> the DropDownList has loaded the data from the database.
>
> I tried placing the code to do this inside the Page_Load() &
> (controlName)_DataBound() events, but the Page_Load() event is called
> before the data is bound and the (controlName)_DataBound() event doesn't
> get called at all (breakpoint not reached when debugging the page).
>
> Not sure if it matters or not, but I am using an ObjectDataSource that
> references a DataSet (.xsd).
>
> What method should I use in order to determine which view is displayed
> at runtime?
>
> -={ Kyle K }=-
>

 
Reply With Quote
 
 
 
 
Kyle K.
Guest
Posts: n/a
 
      06-08-2006
I figured it out (while checking out solution #1 below)...

If the View that contains the DropDownList is not active when the page
is loaded, then the DataBound event won't get fired.

I had left the MultiView's ActiveViewIndex = -1 (default), meaning none
of the views get displayed. I figured that I'd just choose the one to
display at run-time. Once I switched this to show the view that
contained the DropDownList by default, then the DataBound event fired.

Thanks for the help!

-={ Kyle K }=-

Phillip Williams wrote:
> Hi Kyle,
>
> 1- you can get the count while handling the Selected event of the
> objectDataSource. You may look at the code of this demo for an example:
> http://www.webswapp.com/codesamples/...w/default.aspx
>
> 2- the reason your (controlName)_DataBound() event was not fired could be
> that you have not wired the event handler to the event. For example, have
> you added OnDataBound="controlName_DataBound" to the markup of the
> dropdownlist?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
embeding databound DropDownList in FormView spoils DropDownList ev Lagrange ASP .Net Web Controls 1 01-17-2009 08:31 AM
DataBound dropdownlist + extra Item =?Utf-8?B?ZGhucml2ZXJzaWRl?= ASP .Net 4 07-25-2005 12:25 PM
determining datasource item count within ITemplate Alex ASP .Net 1 05-26-2005 02:54 PM
determining a dropdownlist selected item without doing a postback SGSmith ASP .Net Web Controls 1 07-05-2004 11:25 PM
I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not showing the count of the new rows being added Praveen Balanagendra via .NET 247 ASP .Net 2 06-06-2004 07:16 AM



Advertisments