?
Solved

ASP drop down list value for All

Posted on 2014-12-07
5
Medium Priority
?
255 Views
Last Modified: 2014-12-30
Just starting to learn how to convert my classic asp pages to asp.net.

Here is my problem. I have a drop down list at the top of my page that is dynamically populated.

        Choose Asset Type:
        <asp:DropDownList 
            ID="DropDownList1" 
            runat="server" 
            DataSourceID="sdsAssettypes" 
            DataTextField="type" 
            DataValueField="type" 
            AppendDataBoundItems="True" 
            AutoPostBack="True">
            <asp:ListItem Text="Select a asset type" Value=""></asp:ListItem>
            <asp:ListItem Text="All" Value=""></asp:ListItem>
        </asp:DropDownList>
        <asp:SqlDataSource 
            ID="sdsAssettypes" runat="server" 
            ConnectionString="<%$ ConnectionStrings:PortalConnectionString %>" 
            SelectCommand="SELECT DISTINCT [type] FROM [computer_assets]">
        </asp:SqlDataSource>

Open in new window


You will notice at the end I have added a list item for "Select a asset type" and "All".

This works:
 <asp:ListItem Text="Select a asset type" Value=""></asp:ListItem>

Open in new window


Problem is I am not sure what to put as the value for "All" in this one:
<asp:ListItem Text="All" Value=""></asp:ListItem>

Open in new window


I want to have the choice of seeing all records or narrowed down by asset type.

This is where the value will be going:
<asp:SqlDataSource ID="sdsAssets" runat="server" ConnectionString="<%$ ConnectionStrings:PortalConnectionString %>" SelectCommand="SELECT * FROM [computer_assets] WHERE ([type] = @type)" DeleteCommand="DELETE FROM [computer_assets] WHERE [asset_id] = @asset_id" InsertCommand="INSERT INTO [computer_assets] ([type], [computer_name], [ip_address], [user_name], [location], [notes], [operating_system], [login], [password], [wired]) VALUES (@type, @computer_name, @ip_address, @user_name, @location, @notes, @operating_system, @login, @password, @wired)" UpdateCommand="UPDATE [computer_assets] SET [type] = @type, [computer_name] = @computer_name, [ip_address] = @ip_address, [user_name] = @user_name, [location] = @location, [notes] = @notes, [operating_system] = @operating_system, [login] = @login, [password] = @password, [wired] = @wired WHERE [asset_id] = @asset_id">
            <DeleteParameters>
                <asp:Parameter Name="asset_id" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="type" Type="String" />
                <asp:Parameter Name="computer_name" Type="String" />
                <asp:Parameter Name="ip_address" Type="String" />
                <asp:Parameter Name="user_name" Type="String" />
                <asp:Parameter Name="location" Type="String" />
                <asp:Parameter Name="notes" Type="String" />
                <asp:Parameter Name="operating_system" Type="String" />
                <asp:Parameter Name="login" Type="String" />
                <asp:Parameter Name="password" Type="String" />
                <asp:Parameter Name="wired" Type="String" />
            </InsertParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="type" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="type" Type="String" />
                <asp:Parameter Name="computer_name" Type="String" />
                <asp:Parameter Name="ip_address" Type="String" />
                <asp:Parameter Name="user_name" Type="String" />
                <asp:Parameter Name="location" Type="String" />
                <asp:Parameter Name="notes" Type="String" />
                <asp:Parameter Name="operating_system" Type="String" />
                <asp:Parameter Name="login" Type="String" />
                <asp:Parameter Name="password" Type="String" />
                <asp:Parameter Name="wired" Type="String" />
                <asp:Parameter Name="asset_id" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>

Open in new window

0
Comment
Question by:princeservice
[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
  • 2
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 40485641
put as value %, and change:
"SELECT * FROM [computer_assets] WHERE ([type] = @type)"

into:
"SELECT * FROM [computer_assets] WHERE ([type like = @type)"

in the sqldatasource
0
 

Author Comment

by:princeservice
ID: 40485650
Unclosed quotation mark after the character string 'type like = @type)'.
Incorrect syntax near 'type like = @type)'.
0
 

Author Comment

by:princeservice
ID: 40485656
I figured it out. Thanks for the help.

([type] like @type)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40485664
sorry for the = vs = LIKE ...
0
 
LVL 1

Expert Comment

by:kaushik_gajera2002
ID: 40525055
First Add Default value like "All"

DropDownListID.Items.Insert(0, new ListItem("Default text", "Default value")

Than after bind data source to Dropdownlist
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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