Disable databound dropdownlist if 0 items

Discussion in 'ASP .Net Web Controls' started by Evan M., Nov 13, 2006.

  1. Evan M.

    Evan M. Guest

    I'm working on an ASP.NET 2.0 web page right now (using C#), and am
    trying to figure out how I can conditionally disable a drop down linst
    on the page if the datasource that it is bound to has no items.

    I tried in the Page_Load event checking how many items are in the list
    (ddl.Items.Count), but that always returned 0, meaning that it was
    firing the event before the SqlDataSource that is on the page is
    returning its list.

    Any suggestions?
    Thanks
     
    Evan M., Nov 13, 2006
    #1
    1. Advertising

  2. Evan M.

    MikeS Guest

    Check the item count after the list has databound.

    Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal
    e As System.EventArgs) Handles DropDownList1.DataBound
    DropDownList1.Enabled = DropDownList1.Items.Count > 0
    End Sub
     
    MikeS, Nov 13, 2006
    #2
    1. Advertising

  3. Evan M.

    Evan M. Guest

    That got it.

    Thanks
     
    Evan M., Nov 13, 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. rodchar
    Replies:
    0
    Views:
    411
    rodchar
    Nov 26, 2007
  2. Cirene
    Replies:
    5
    Views:
    503
    Cirene
    Jun 8, 2008
  3. Andy B.
    Replies:
    2
    Views:
    712
    Andy B.
    Feb 19, 2009
  4. Manu
    Replies:
    0
    Views:
    189
  5. Lagrange
    Replies:
    1
    Views:
    584
    Lagrange
    Jan 17, 2009
Loading...

Share This Page