Solved

Dropdown list as query criteria

Posted on 2009-04-14
7
282 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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