Solved

Dropdown list as query criteria

Posted on 2009-04-14
7
286 Views
Last Modified: 2013-11-26
Hi, I have one dropdown list, populated with a database table that acts as a query criteria. Everything works fine. However, how can I add a blank value in the dropdown list, ontop of the other values, so it acts as a return all values ? Thanks
0
Comment
Question by:GPSAddict
[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
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24141214
Hi,

To add a blank value in the top of a dropdown list

DropDownList1.Items.Insert(0, new ListItem(string.Empty, string.Empty))
0
 

Author Comment

by:GPSAddict
ID: 24141407
GiftsonDJohn: what event should I use ?
0
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 500 total points
ID: 24141439
On the Page_Load event after you bind the dropdown list, you can use the function.

ex.

DropDownList1.DataSource=DataTable1;
DropDownList1.DataTextField="Column1";
DropDownList1.DataValueField="Column2";
DropDownList1.DataBind();

//Data Binding is Complete. Now we can add blank item into dropdownlist

DropDownList1.Items.Insert(0, new ListItem(string.Empty, string.Empty));
0
Technology Partners: 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!

 

Author Comment

by:GPSAddict
ID: 24144328
GiftsonDJohn: The reason I was asking is I didn't write a single line of code...everything going through the objects...So is there an event that happens just after the binding is complete ? Thanks
0
 

Author Comment

by:GPSAddict
ID: 24158918
Hello ?
0
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24161881
Hi,

Sorry. Got held in my work. All the Data Bound Control will fire DataBound event after every bindings. If you want to code for to return all values if blank value is selected then you have to write query so that it checks for the blank value and return the entire data.

if(DropDownList1.SelectedValue().Equals(string.Empty))
{
    //Query to extract all records
}
else
{
   //Query to extract record based on the dropdown value
}
0
 

Author Comment

by:GPSAddict
ID: 24167603
Doesn't seem to work, index 0 is already used since the dropdownlist is already populated with my database items ?! Anymore ideas ? Thanks
0

Featured Post

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!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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