Solved

ASP drop down list value for All

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

12 Experts available now in Live!

Get 1:1 Help Now