Wrox Programmer Forums
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 10th, 2012, 05:40 AM
Authorized User
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default DropDowList problem

Hi there, I need your help.
Here is my problem.

I have this DropDownList populate with this query in dbms SQL Server 2008:

            sql2 = "SELECT * FROM dbo_40 " +                         
                         " ORDER BY " +
                         " Sort;";
            dadapter = new SqlDataAdapter(sql2, ConnSqlServer);
            dset = new DataSet();
            DropDownList3.DataSource = dset.Tables[0];
            DropDownList3.DataTextField = "MAT";
            DropDownList3.DataValueField = "Sort";
In this DDL I need add the ALL value and tried this code:
                        <asp:DropDownList ID="DropDownList3" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
                            Font-Size="10pt" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged">
                            <asp:ListItem Value="%">---</asp:ListItem>
                            <asp:ListItem Value="5">ALL</asp:ListItem>

    public void GridViewBind()
        sql1 = "SELECT TOP 1000 * FROM dbo_40;";

            if (DropDownList3.SelectedIndex == 5)
                sql1 = "SELECT * FROM dbo_40 WHERE sID = 5;";


    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
But in the code-behind the value DropDownList3.SelectedIndex for ALL it's null or empty.

Can you help me?
Thanks in advance.
Old August 10th, 2012, 09:40 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

Your "5" element has an index of 1, not 5. So SelectedIndex is not going to work. Instead, look at SelectedItem.Value.

Hope this helps,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
cms9651 (August 10th, 2012)
Old August 10th, 2012, 10:52 AM
Authorized User
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts

Thanks you very much for your help.
I'm really happy for your quickly answer.
Good bye.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting All from Dropdowlist taboadar ASP.NET 2.0 Professional 1 January 12th, 2009 11:52 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.