Determining item count of databound DropDownList

Discussion in 'ASP .Net Web Controls' started by Kyle K., Jun 8, 2006.

  1. Kyle K.

    Kyle K. Guest

    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 }=-
     
    Kyle K., Jun 8, 2006
    #1
    1. Advertising

  2. 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/aspnet20/dropdownlist_gridview/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 }=-
    >
     
    Phillip Williams, Jun 8, 2006
    #2
    1. Advertising

  3. Kyle K.

    Kyle K. Guest

    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/aspnet20/dropdownlist_gridview/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?
     
    Kyle K., Jun 8, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    1
    Views:
    479
    gsnke
    May 26, 2005
  2. =?Utf-8?B?ZGhucml2ZXJzaWRl?=

    DataBound dropdownlist + extra Item

    =?Utf-8?B?ZGhucml2ZXJzaWRl?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    5,189
    Eliyahu Goldin
    Jul 25, 2005
  3. rodchar
    Replies:
    0
    Views:
    400
    rodchar
    Nov 26, 2007
  4. Manu
    Replies:
    0
    Views:
    178
  5. Lagrange
    Replies:
    1
    Views:
    573
    Lagrange
    Jan 17, 2009
Loading...

Share This Page