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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:49:14+00:00 2026-05-21T02:49:14+00:00

I have a ASP:DropDown list which is populated by the following: public void Fill1()

  • 0

I have a ASP:DropDown list which is populated by the following:

public void Fill1()
{
    string connectionString = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
    using (SqlConnection _con = new SqlConnection(connectionString))
    using (SqlCommand cmd = new SqlCommand("SELECT * FROM Products", _con))
    {
        cmd.Connection.Open();

        SqlDataReader ddlValues;
        ddlValues = cmd.ExecuteReader();

        txtProduct.DataSource = ddlValues;
        txtProduct.DataValueField = "Description";
        txtProduct.DataTextField = "Description";
        txtProduct.DataBind();

        cmd.Connection.Close();
        cmd.Connection.Dispose();
    }
}

I need to call the SalesPrice from same table and based on the selected value in the drop down update a ASP:TextBox Field called txtUnitAmount.

I have tried writing it into the same function and it wont let me set the .Text value for the ASP:TextBox. Can any one suggest a way to achieve this?

Thanks to all for their help so far!

Cheers

Justin

Extra Code for Discussion

public void Fill2()
    {
        string getProdValue = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
        using (SqlConnection _con = new SqlConnection(getProdValue))
        using (SqlCommand cmd = new SqlCommand("SELECT SalesPrice FROM Products WHERE Description = " + Request.Form["txtProduct"].ToString(), _con))
        {
            int getProdCost = (int)cmd.ExecuteScalar();
            txtUnitAmount.Text = getProdCost.ToString("###,###0.000");
        }           
    }
  • 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-05-21T02:49:15+00:00Added an answer on May 21, 2026 at 2:49 am

    The question is a little hard to follow, but I will give it a stab.

    You going to have to do another query to the DB based on the onChnge event produced by the drop down change.

    You need to wire up the OnChange event for the dropdown and enable autopostback. This can be done through the properties explorer. From the OnChangeEvent, fire your code

    Note this code is far from production. You need to do input and return sanitization.

    var description = Request.Form["txtProduct"].ToString();
    using (SqlConnection _con = new SqlConnection(getProdValue))
    using (SqlCommand cmd = new SqlCommand("SELECT UnitPrice FROM Products WHERE Description = '" + description "'", _con))
    {
        cmd.Connection.Open();
        var unitPrice = cmd.ExecuteScalar();
        txtUnitPrice.Text= unitPrice.ToString("###,###0.000");       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a repeater with a literal, a dropdown list, and a button. <asp:Repeater
I have an ASP.NET DropDownList control that renders into a dropdown list (select HTML
I have the webform with dropdown list, label and textbox. Like below: <asp:DropDownList ID=ddlTest
I have the following JavaScript to toggle a dropdownlists in a ASP.NET page, which
I have a dropdown list which is in updatepanel. I have to fill that
i have an asp.net mvc page and i want to have a dropdown list
I have asp:DropDownList control which i want to display data to user who don't
I have an ASP.NET webform on which I use a DropDownList control to allow
I'm building an asp.net cutom control inside which I have two dropdownlists: companyIdSelection and
I have an ASP.NET MVC application. I am having multiple drop-down list in my

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.