Solved

ASP drop down list value for All

Posted on 2014-12-07
5
252 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 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

732 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