Solved

Dropdown list as query criteria

Posted on 2009-04-14
7
280 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now