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 8919195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:57:27+00:00 2026-06-15T05:57:27+00:00

I have a asp.net page listing products (pulled from a database) with edit/delete buttons.

  • 0

I have a asp.net page listing products (pulled from a database) with edit/delete buttons. The user can edit the product by clicking the edit button. I’ve been able to pull in data from the db to the textboxes based on the product selected. However, I am getting duplicate items in the dropdown box. It’s only supposed to have 32 items and has 160 items (each item is appearing 5 times). I’ve used Items.Clear() but am still getting duplicates. Also the dropbox just shows the first item in the list rather than the appropriate item for that product that is currently in the db. Can anyone see what I may be doing wrong?

Thanks.

 protected void Page_Load(object sender, EventArgs e)
    {
        this.Master.HighlightNavItem("Products");
        string Mode = (Request.QueryString["Mode"]);

        //Upon opening page, if this is an edit to existing product (populate product data)
        if (Mode == "E")
        {
            if (!IsPostBack)
            {
                int ProductID = Int32.Parse(Request.QueryString["ID"]);

                //Declare the connection object
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;

                //Connect to the db
                Conn.Open();

                //Define the query                    
                //string sql = "SELECT dbo.Vendor.VendorName, dbo.Vendor.VendorID, dbo.Product.ProductName, dbo.Product.ProductNumber, dbo.lu_Category.CategoryID, dbo.lu_Category.Description FROM dbo.Product INNER JOIN dbo.Vendor ON dbo.Product.VendorID = dbo.Vendor.VendorID INNER JOIN dbo.lu_Category ON dbo.Product.CategoryID = dbo.lu_Category.CategoryID WHERE ProductID=@ProductID";
                string sql = "SELECT ProductName, ProductNumber, ProductDescription, Cost, Markup, Unit, QtyOnHand, ShippingWeight, dbo.Vendor.VendorID, VendorName, dbo.lu_Category.CategoryID, Description FROM Vendor, Product, lu_Category WHERE ProductID=@ProductID";

                //Declare the Command
                SqlCommand cmd = new SqlCommand(sql, Conn);

                //Add the parameters needed for the SQL query
                cmd.Parameters.AddWithValue("@ProductID", ProductID);

                //Declare the DataReader
                SqlDataReader dr = null;

                //Fill the DataReader
                dr = cmd.ExecuteReader();

                //Loop through the DataReader
                ddlVendor.Items.Clear();
                while (dr.Read())
                {

                    txtProductName.Text = dr["ProductName"].ToString();
                    txtProductNo.Text = dr["ProductNumber"].ToString();
                    txtDescription.Text = dr["ProductDescription"].ToString();
                    txtCost.Text = dr["Cost"].ToString();
                    txtMarkup.Text = dr["Markup"].ToString();
                    txtUnit.Text = dr["Unit"].ToString();
                    txtQty.Text = dr["QtyOnHand"].ToString();
                    txtWeight.Text = dr["ShippingWeight"].ToString();
                    ListItem li = new ListItem();
                    li.Text = dr["VendorName"].ToString();
                    li.Value = dr["VendorID"].ToString();
                    ddlVendor.Items.Add(li);
  • 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-15T05:57:28+00:00Added an answer on June 15, 2026 at 5:57 am

    You should change your SQL query and remove the , type of joins.
    Then test your query directly in your database to make sure you don’t get doubles.

    The rest of your code looks fine so i’m sure testing your query will solve your problem.
    Do not use Comma Joins it’s deprecated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET page where I am showing products in a Gridview control.
I have an asp.net web page which interacts with a SQL Server database, grabs
I have an ASP.NET 4.0 home page which displays about 20 product listings. Each
I have an ASP.NET page with 10 dynamically generated LinkButton elements. When a user
I have asp.net page dropdownlist and button when choose my group from dropdownlist and
I have asp.net page where some file manipulation is performed. So when user click
I have a ASP.NET page that contains both javascript and ASP.NET user controls. When
I have an asp.net page where i do some search on the database to
I have ASP.NET page with an iframe on it for displaying some pdf reports
I have ASP.NET page, it calls webservice via $.ajax and returns result in json

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.