Disable databound dropdownlist if 0 items

E

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
 
M

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
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top