Solved

Cannot check when DropDownList is empty

Posted on 2009-05-16
6
253 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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