4
Answers

Select All Dropdown Lists

Kristin Lacy

Kristin Lacy

15y
3.7k
1

Hi,
I'm fairly new to C# and SQL.  I'm trying to build a search tool for a system that I am helping to build.  What I am wanting to do is simply add 'select all' to a database bound drop down list so that when users choose select all from the list and clicks search it will search all of the items in the dropdown list
My pretty basic code so far is:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="fileName" DataValueField="fileName" AppendDataBoundItems="True">
<asp:ListItem Value="-1"> Select All</ListItem>
</asp:DropDownList>
Now how do I get it recognise that when the user clicks on Select All that it should search all of the items in the dropdown list?  Any help would be greatly appreciated :)
Thanks
Kristin
 
Answers (4)
0
Sam Hobbs

Sam Hobbs

55 29.3k 2.1m 15y
I think there is a simple solution. I think you do not need to add a separate item for a Search All. The user can select all items using Ctrl-A or something else. Then when you process the DropDownList (clicks search), the number of selected items would be the same as the total number of items in the control. So just check the selected items and if it is the same as the total number of items in the control, then you don't need to process the selections; just do the query without the filter for the items in the DropDownList.
0
Kirtan Patel

Kirtan Patel

NA 21.9k 4.1m 15y
Friend,

you can handle it using Simple if Condition

just give you rough idea how to do it .

if ( DropDownlist1.SelectedItem.ToString() == "--Select All --")
{
       //Code to Search Every Item Except Select All 
 
 
}
else
{
      ///Code to Search Just Single Item
}

   
if still not resolve then .

Send me Your Code  I will Modify your Code to get desired Output you want .

Send Me Your Project Files+Database (zip) to me in mail kirtan007@gmail.com
0
Kristin Lacy

Kristin Lacy

NA 3 0 15y

I can't really add the items manually as there are quite a lot of them and would be easier for them to be added to list automatically via the the databound option.  If I inserted the Select All to my database how I would then get it to do action of selecting all items in the dropdown list when a user clicks on it?
 
Thanks
0
Kirtan Patel

Kirtan Patel

NA 21.9k 4.1m 15y
Friend,

you can not Normally ad Select All in Data Bound Combo Box ..

you need to Add "Select all " in your database so that it shown in DropDown List

so just add Value ---Select All --- in your database .

Another way of doing it is By Fill the Combobox By DataReader Just add --Select All -- as First Item

then Add Item One By One .in Dropdown list

Friend, if You Still need Assistance then let me know .