Solved

Cannot check when DropDownList is empty

Posted on 2009-05-16
6
254 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
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

631 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