Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot check when DropDownList is empty

Posted on 2009-05-16
6
Medium Priority
?
255 Views
Last Modified: 2013-12-17
I have a ddl that is being populated when the page loads. What I need to do is set the status of a button to enable of false if the ddl has 0 items. Any suggestions?

<asp:DropDownList ID="ddlP" runat="server" DataSourceID="SqlDataSource1" 
                                                            DataTextField="FullName" DataValueField="PId">
                                                        </asp:DropDownList>
                                                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                                            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                                                            
                                                        SelectCommand="SELECT blah... " 
                                                        ondatabinding="SqlDataSource1_DataBinding">
                                                            <SelectParameters>
                                                                <asp:ProfileParameter Name="UserId" PropertyName="SCId" 
                                                                    Type="String" />
                                                            </SelectParameters>
                                                        </asp:SqlDataSource>                                                    
 
 
    protected void SqlDataSource1_DataBinding(object sender, EventArgs e)
    {
        //if (e.AffectedRows == 0) //no good
        if (ddlPatients.Items.Count == 0)
        {
            btnAdd.Enabled = false; //ignored
        }
        else
        {
            btnAdd.Enabled = true; //always the case regardless
        }
    }

Open in new window

0
Comment
Question by:fwstealer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24403114
if (ddlPatients.Items.Count == 0)
        {
            btnAdd.Enabled = false; //ignored
        }
        else
        {
            btnAdd.Enabled = true; //always the case regardless
        }


keep this part in page load and try it
0
 

Author Comment

by:fwstealer
ID: 24403161
same - it is always true
0
 

Author Comment

by:fwstealer
ID: 24403165
pageload is where i began then move to the SqlDataSource1_DataBinding
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 2000 total points
ID: 24403181
Try keeping this  in dropdown list databound event
0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24403887
Try using your if...else code in the Selected event of the SqlDataSource rather than DataBinding.
0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24403888
You may also move your code into Page_PreRender event.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question