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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:55:57+00:00 2026-06-11T15:55:57+00:00

This is mi first post. I´m using Visual Studio to make an Azure application.

  • 0

This is mi first post.
I´m using Visual Studio to make an Azure application.

I want to do an “Update page”.

this are de steps that i want to implement:

1) The user selects one ID from the DropDownList

2) The user pushes an HTML Button

3) The “System” fill some TextBoxs whith information from a SQL sentence:
Select…where Id= DropDownList1.SelectedValue.ToString()

4) The User can change some information on the TextBoxs and push an ASP Button

5) The System do a SQL UPDATE sentence whith the information of the TextBoxs

I´ve got One DropDownList, IDPRODUCT

<asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="index_Changed"  runat="server" ></asp:DropDownList> 

I fill it from a SQL sentence on “Page Load”

DropDownList1.Items.Clear();
            DropDownList1.Items.Add(" ");

            string consultaComboIdCompra = "SELECT DISTINCT IdCompra FROM Compras";
            SqlCommand sqlCommandComboIdCompra = new SqlCommand(consultaComboIdCompra, sqlConnection);
            sqlConnection.Open();
            SqlDataReader readerComboIdCompra = sqlCommandComboIdCompra.ExecuteReader();


            if (readerComboIdCompra.HasRows)
            {
                while (readerComboIdCompra.Read())
                {
                    DropDownList1.Items.Add(readerComboIdCompra.GetString(0));
                }
            }

            sqlConnection.Close();

I´ve one HTML Button, it´s function should be to fill some TextBox with the result of a SQL sentence, like:

 string consulta2 = "SELECT Unidades FROM Productos WHERE IdProducto = '" + DropDownList1.SelectedValue.ToString() + "'";
 SqlCommand sqlCommand2 = new SqlCommand(consulta2, sqlConnection);
 sqlConnection.Open();
 SqlDataReader reader2 = sqlCommand2.ExecuteReader();

 if (reader2.HasRows)
 {
   while (reader2.Read())
   {

       TextBox4.Text = reader2.GetString(0);
   }
 }
 sqlConnection.Close();

For last i´ve implemented the UPDATE sentence

if (IsPostBack)
            {
string idCompra = DropDownList1.SelectedValue.ToString();

string consulta3 = "UPDATE Compras SET Unidades = '" + TextBox1.Text + "' WHERE IdCompra = '" + idCompra + "'";
                SqlCommand sqlCommand3 = new SqlCommand(consulta3, sqlConnection);
                sqlConnection.Open();
                SqlDataReader reader3 = sqlCommand3.ExecuteReader();
                sqlConnection.Close();

}

I cant “autoanswer”, so i edit my ask
The code that finally works, thanks to nunespascal, is the next one:

 public partial class WebFormProductosOpcion5 : System.Web.UI.Page
        {
            static string strSQLconnection = *********
            static SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
            protected void Page_Load(object sender, EventArgs e)
            {
                if(!IsPostBack)
                {
                DropDownList1.Items.Clear();
                DropDownList1.Items.Add(" ");

                string consultaComboIdProducto = "SELECT DISTINCT IdProducto FROM Productos";
                SqlCommand sqlCommandComboIdProducto = new SqlCommand(consultaComboIdProducto, sqlConnection);
                sqlConnection.Open();
                SqlDataReader readerComboIdProducto = sqlCommandComboIdProducto.ExecuteReader();


                if (readerComboIdProducto.HasRows)
                {
                    while (readerComboIdProducto.Read())
                    {
                        DropDownList1.Items.Add(readerComboIdProducto.GetString(0));
                    }
                }

                sqlConnection.Close();



            }

            }

            protected void html_click(object sender, EventArgs e)
            {
                TextBox2.Text = "HOLA";
                Debug.WriteLine("HOLA");



            }



            protected void HTML_Button_Click(object sender, EventArgs e)
            {
                string idProductoSeleccionado = DropDownList1.SelectedValue.ToString();
                string consultaUltimo = "SELECT * FROM Productos WHERE IdProducto = '" + idProductoSeleccionado + "'";
                SqlCommand sqlCommandUltimo = new SqlCommand(consultaUltimo, sqlConnection);
                sqlConnection.Open();
                SqlDataReader readerUltimo = sqlCommandUltimo.ExecuteReader();

                if (readerUltimo.HasRows)
                {
                    while (readerUltimo.Read())
                    {
                        //Put the name
                        TextBox2.Text = readerUltimo.GetString(1);
                    }
                }

                sqlConnection.Close();
                //Label10.Text = col1;
                sqlConnection.Close();
            }



            protected void Button1_Click(object sender, EventArgs e)
            {

                    //string consulta = "select * from Productos where IdProducto ='";
                    //consulta = consulta + idP + "'";
                    SqlCommand sqlCommand = new SqlCommand(consulta, sqlConnection);
                    sqlConnection.Open();
                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    sqlConnection.Close();
                    //Mensaje Modificación Correcta
                    Response.Write("<script language=javascript>alert('Modificado con éxito');</script>");




            }
        }
  • 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-11T15:55:58+00:00Added an answer on June 11, 2026 at 3:55 pm

    You need to bind a DropDownList only the first time a user requests the page.
    Check that the user is not posting back before binding on Page Load

    if(!IsPostBack)
    {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add(" ");
    
            string consultaComboIdCompra = "SELECT DISTINCT IdCompra FROM Compras";
            SqlCommand sqlCommandComboIdCompra = new SqlCommand(consultaComboIdCompra, sqlConnection);
            sqlConnection.Open();
            SqlDataReader readerComboIdCompra = sqlCommandComboIdCompra.ExecuteReader();
    
    
            if (readerComboIdCompra.HasRows)
            {
                while (readerComboIdCompra.Read())
                {
                    DropDownList1.Items.Add(readerComboIdCompra.GetString(0));
                }
            }
    
            sqlConnection.Close();
    }
    

    Since you are updating on a button, you need not check for IsPostBack. Put that code on the button Click event handler. That way it would run only when someone clicks your update button

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

Sidebar

Related Questions

this is my first post here! I'm trying to make a windows forms program
Using Visual Studio 2010 beta, when I run my application within the IDE for
Using Visual Studio 2008 and Boost Libraries 1.46.1 I want to compile and link
First, some basic details: I'm using Visual Studio 2008 Team Edition I'm using C#
Using Visual Studio 2010, I developed a WCF service hosted on a web application
I am writing an ASP.NET web application using Visual Studio 2008. The project is
This is my first post here, but I've using this site regularly to help
this is my first post at stackoverflow. I am using the Facebook Graph Batch
I have a VERY simple C# Winforms project that I made using Visual Studio
I'm just starting my first C++ project. I'm using Visual Studio 2008 . It's

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.