Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dropdown list as query criteria

Posted on 2009-04-14
7
Medium Priority
?
289 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 2000 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

730 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