Solved

ASP drop down list value for All

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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.…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now