Home All Groups Group Topic Archive Search About

Disable databound dropdownlist if 0 items

Author
13 Nov 2006 8:39 PM
Evan M.
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

Author
13 Nov 2006 8:54 PM
MikeS
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
Author
13 Nov 2006 9:14 PM
Evan M.
That got it.

Thanks