Solved

ASP drop down list value for All

Posted on 2014-12-07
5
246 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
  • 2
  • 2
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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 142

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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