Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:39:21+00:00 2026-06-16T00:39:21+00:00

I want to sort a drop down list by price but it doesn’t work.

  • 0

I want to sort a drop down list by price but it doesn’t work. I have the error like the following:

Incorrect syntax near ‘=’.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:
System.Data.SqlClient.SqlException: Incorrect syntax near ‘=’. Source
Error: Line 72: reader = cmd.ExecuteReader();

Here are my codes

New Arrivals.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class NewArrivals : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        if(IsPostBack)
        {
            bindDropDownList();
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList();
    }
    public void bindDropDownList()
    {
        DropDownList1.DataTextField = "price";
        DropDownList1.DataSource = getReader();
        DropDownList1.DataBind();

        DropDownList1.Items.Insert(0, new ListItem("-Select-"));
        DropDownList1.Items.Insert(1, new ListItem("Price - Highest to Lowest"));
        DropDownList1.Items.Insert(2, new ListItem("Price - Lowest to Highest"));

    }
    public SqlDataReader getReader()
{
    SqlDataReader reader = null;
    DataTable DataList1 = new DataTable();

    if(DropDownList1.Text == "-Select-")
    {
        SqlConnection myConnect = new SqlConnection();
        myConnect.ConnectionString = ConfigurationManager.ConnectionStrings["ProductCS"].ConnectionString;

        string strCommandText ="SELECT * FROM [tb_ListPdts] WHERE newPdt=1";

        SqlCommand cmd = new SqlCommand(strCommandText, myConnect);

        cmd.CommandText = strCommandText;
        cmd.Connection = myConnect;

        myConnect.Open();
        reader = cmd.ExecuteReader();
        DataList1.Load(reader);
        myConnect.Dispose();
        cmd.Dispose();

    }
    else if (DropDownList1.SelectedValue == "Price - Highest to Lowest")
    {
        SqlConnection myConnect = new SqlConnection();
        myConnect.ConnectionString = ConfigurationManager.ConnectionStrings["ProductCS"].ConnectionString;

        string strCommandText = "SELECT [image], [productName], [price], [newPdt] FROM [tb_ListPdts] WHERE newPdt==1 ORDER BY price desc";

        SqlCommand cmd = new SqlCommand(strCommandText, myConnect);

        cmd.CommandText = strCommandText;
        cmd.Connection = myConnect;

        myConnect.Open();
        reader = cmd.ExecuteReader();
        DataList1.Load(reader);
        myConnect.Dispose();
        cmd.Dispose();

    }

    else if (DropDownList1.DataTextField == "Price - Lowest to Highest")
    {
        SqlConnection myConnect = new SqlConnection();
        myConnect.ConnectionString = ConfigurationManager.ConnectionStrings["ProductCS"].ConnectionString;

        string strCommandText = "SELECT [image], [productName], [price], [newPdt] FROM [tb_ListPdts] WHERE newPdt==1 ORDER BY price asc";

        SqlCommand cmd = new SqlCommand(strCommandText, myConnect);

        cmd.CommandText = strCommandText;
        cmd.Connection = myConnect;

        myConnect.Open();
        reader = cmd.ExecuteReader();
        DataList1.Load(reader);
        myConnect.Dispose();
        cmd.Dispose();

    }
    return reader;
}
}

New Arrivals.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="NewArrivals.aspx.cs" Inherits="NewArrivals" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style2
        {
            width: 80%;
        }
    </style>
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p id="product">New Products</p>
            <hr />

    <br />

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" AppendDataBoundItems="true"
        onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
        <asp:ListItem>-Select-</asp:ListItem>
            <asp:ListItem>Price - Highest to Lowest</asp:ListItem>
            <asp:ListItem>Price - Lowest to Highest</asp:ListItem>
    </asp:DropDownList>
    <br />

    <br />
    <table class="style2" id="newTable" rules="groups">
        <tr>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                <asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84" 
                    BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
                    CellSpacing="2" GridLines="Both" 
                    RepeatColumns="3" RepeatDirection="Horizontal">
                    <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                    <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                    <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                    <ItemTemplate>
                        <asp:Image ID="Image1" ImageUrl= '<%# Eval("image") %>'
                            runat="server" Height="180px" Width="230px" />
                        <br />
                        <asp:Label ID="productNameLabel" runat="server" 
                            Text='<%# Eval("productName") %>' />
                        <br />
                        Price: $
                        <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>' />
                        <br />
                        <asp:Label ID="newPdtLabel" runat="server" Text='<%# Eval("newPdt") %>' Visible="False" />
                        <br />
                        <br />
                    </ItemTemplate>
                    <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                </asp:DataList>
            </td>
        </tr>
    </table>
    </asp:Content>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:39:22+00:00Added an answer on June 16, 2026 at 12:39 am

    Your select statement is wrong. You are using equal comparator as == in your where clause. SQL Server T-SQL does not use C-style equals, instead a single = operator is used.

    Update this statement

    FROM [tb_ListPdts] WHERE newPdt==1 ORDER BY price asc
    

    to use a single = operator as below:

    FROM [tb_ListPdts] WHERE newPdt=1 ORDER BY price asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to sort a list of integer values, but before sorting them I
I have a drop down list on a page, by default the option that
I have a drop down list on one form that populates a puzzle id
I want to sort the items that have been previously selected with checkboxes. If
I want to sort list items by their priority, which the user types in,
I want to sort an array by 'hits', but I also want to look
i want to sort dictionary based upon value of each dictioanry item.but if i
I have a drop list in gridview In which I am selecting a data
So, basically I have this select / drop down menu that I use AJAX
I'm new to php and I'm having a problem. I have three drop down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.