Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 10th, 2012, 05:40 AM
Authorized User
Points: 121, Level: 2
Points: 121, Level: 2 Points: 121, Level: 2 Points: 121, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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:

Code:
            sql2 = "SELECT * FROM dbo_40 " +                         
                         " ORDER BY " +
                         " Sort;";
            dadapter = new SqlDataAdapter(sql2, ConnSqlServer);
            dset = new DataSet();
            dadapter.Fill(dset);
            DropDownList3.DataSource = dset.Tables[0];
            DropDownList3.DataTextField = "MAT";
            DropDownList3.DataValueField = "Sort";
            DropDownList3.DataBind();
In this DDL I need add the ALL value and tried this code:
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>
                        </asp:DropDownList>


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


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

    }

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

Can you help me?
Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old August 10th, 2012, 09:40 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
cms9651 (August 10th, 2012)
  #3 (permalink)  
Old August 10th, 2012, 10:52 AM
Authorized User
Points: 121, Level: 2
Points: 121, Level: 2 Points: 121, Level: 2 Points: 121, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:43 PM.


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