Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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
  #1 (permalink)  
Old May 23rd, 2007, 01:27 PM
Authorized User
 
Join Date: May 2007
Location: Fairfax, va, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default dealing with drop downs

I have a drop down list that is populated by a sql query. I either need to be able to add a blank value to the drop down list or be able to disable it so that its value isn't sent to my search procedure. When I select a certain radio button, I set this particular drop down list to enable = False in my VB.net code. This does not allow the user to click on the dropdown but the value that it is sitting on (in this case 100), still gets sent to my procedure. I would like to add a blank value (so it is blank, 100, 200, etc and the blank is the one currently in view). If I can't do that, is it possible to set the value to blank/nothing in the VB code?

Thanks
Lisabb
  #2 (permalink)  
Old May 24th, 2007, 02:04 PM
Authorized User
 
Join Date: May 2007
Location: Fairfax, va, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If there is no way to do this... should i just add a text box to move the value to?

  #3 (permalink)  
Old May 24th, 2007, 03:09 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In code, after you have pouplated the list with data from sql, do this:

dropdownlist.Items.Insert(0, "");
hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #4 (permalink)  
Old May 25th, 2007, 07:28 AM
Authorized User
 
Join Date: May 2007
Location: Fairfax, va, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this command in the page load Sub in my VB.net code but it didn't work. My code is:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.dlPatrolArea.Items.Insert(0, "")
    End Sub
I tried (1,"") but got a error saying that the value must be a non-negative and not be greater than the index. How can I set the index in Visual Studio 2005? Is it the Z-index?

Thanks
  #5 (permalink)  
Old May 25th, 2007, 07:36 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First, when talking about web design, the Z-Index is a positing element used in CSS and has nothing to do with the values in your dropdown.

Secondly, the reason you got an error when you tried to place an item at index 1 is because if you don't have a value at index 0 hence index 1 can't exist.

Lastly, call your Insert AFTER you have databound the control to its datasource. This code below works as it is expected (C#)

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.drp.Items.Insert(0, "");
            this.drp.Items.Insert(1, "foo");
        }
    }

My ddl, when rendered, has a blank entry and then the element foo.

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #6 (permalink)  
Old May 28th, 2007, 12:29 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. sorry Doug i have another idea: use a SQL with an Union.. something like

Code:
SELECT     ''
UNION
SELECT     yoursfields
FROM         yourtable
or
Code:
SELECT     0, ''
UNION
SELECT     *
FROM         yourtable
(if you have a numeric field and a string one...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Drop downs - 2 col socoolbrewster CSS Cascading Style Sheets 5 December 22nd, 2007 05:32 AM
dependent drop downs p2pMember ASP.NET 1.0 and 1.1 Professional 0 July 19th, 2006 05:25 AM
Drop downs for choosing # of pages gilgalbiblewheel Classic ASP Databases 3 October 21st, 2004 03:12 PM
Day of week Drop Downs jeffbarclay Javascript How-To 5 November 17th, 2003 08:28 PM





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