p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   dealing with drop downs (http://p2p.wrox.com/showthread.php?t=58263)

lisabb May 23rd, 2007 01:27 PM

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

lisabb May 24th, 2007 02:04 PM

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


dparsons May 24th, 2007 03:09 PM

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
================================================== =========

lisabb May 25th, 2007 07:28 AM

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

dparsons May 25th, 2007 07:36 AM

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
================================================== =========

gbianchi May 28th, 2007 12:29 AM

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
================================================== =========


All times are GMT -4. The time now is 12:35 AM.

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