Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. dropdownlist

dropdownlist

Scheduled Pinned Locked Moved ASP.NET
database
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mylogics
    wrote on last edited by
    #1

    hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }

    P K H K 4 Replies Last reply
    0
    • M mylogics

      hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      check whether you have given autopostback property to both the dropdown

      Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

      M 1 Reply Last reply
      0
      • P padmanabhan N

        check whether you have given autopostback property to both the dropdown

        Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

        M Offline
        M Offline
        mylogics
        wrote on last edited by
        #3

        yaa i hav made both dropdown autopostback property to true....

        M D 2 Replies Last reply
        0
        • M mylogics

          yaa i hav made both dropdown autopostback property to true....

          M Offline
          M Offline
          mylogics
          wrote on last edited by
          #4

          its not workin yet...

          P 1 Reply Last reply
          0
          • M mylogics

            hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }

            K Offline
            K Offline
            khuzwayom
            wrote on last edited by
            #5

            Is the AutoPostBack property of that dropdown set to True?

            MP

            M 1 Reply Last reply
            0
            • M mylogics

              yaa i hav made both dropdown autopostback property to true....

              D Offline
              D Offline
              DoctorMick
              wrote on last edited by
              #6

              Make sure you have wired the event up properly in your aspx page, i.e. Also, put a breakpoint at the start of your DropDownList2_SelectedIndexChanged method to see if it is being called at all.

              1 Reply Last reply
              0
              • K khuzwayom

                Is the AutoPostBack property of that dropdown set to True?

                MP

                M Offline
                M Offline
                mylogics
                wrote on last edited by
                #7

                yaa...

                1 Reply Last reply
                0
                • M mylogics

                  hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }

                  H Offline
                  H Offline
                  haleemasher
                  wrote on last edited by
                  #8

                  i have done the same thing which u want i just use daset instead of datareader try it

                  protected void Page\_Load(object sender, EventArgs e)
                  {
                      DAL Helper = new DAL();
                   // DataSet ds = new DataSet();
                  Helper.ConnectionString = "Data Source=.\\\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Coupon Management.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                  //  SqlCommand txtcmd = new SqlCommand();
                    //  commandText ="'"+txtAmount .AutoPostBack +"'";
                  
                      string query = "select CouponName from CouponType";
                    ds = Helper.ExecuteDataSet(CommandType.Text, query, null);
                  
                    if (!IsPostBack)
                    {
                        ddlCType.DataSource = ds;
                        ddlCType.DataValueField = "CouponName";
                        ddlCType.DataTextField = "CouponName";
                        ddlCType.DataSourceID = String.Empty;
                    }
                  }
                  
                  protected DataSet GetData(string sqlCommand)
                  {
                  
                     da1  = new SqlDataAdapter(sqlCommand, cnx );
                     ds  = new DataSet();
                     da1.Fill(ds );
                      return ds ;
                  
                  }
                  

                  protected void DropDownList1_TextChanged(object sender, EventArgs e)
                  {
                  cnx.Open();
                  SqlCommand ddlcmd = new SqlCommand();
                  commandText = "SELECT MAX(CouponTransaction.SerialEnd),CouponType.Price FROM CouponType INNER JOIN CouponTransaction ON CouponType.CouponTypeID = CouponTransaction.CouponTypeID WHERE CouponType.CouponName= '" + ddlCType.SelectedValue + "'GROUP BY CouponType.Price";
                  ds = new DataSet();
                  ds = GetData(commandText);
                  if (ds.Tables[0].Rows.Count!=0 )
                  {
                  txtSFrom.Text = ds.Tables[0].Rows[0][0].ToString();
                  Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
                  cnx.Close();
                  }
                  }

                  M 1 Reply Last reply
                  0
                  • M mylogics

                    hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }

                    K Offline
                    K Offline
                    KhandelwalA
                    wrote on last edited by
                    #9

                    Use google

                    1 Reply Last reply
                    0
                    • H haleemasher

                      i have done the same thing which u want i just use daset instead of datareader try it

                      protected void Page\_Load(object sender, EventArgs e)
                      {
                          DAL Helper = new DAL();
                       // DataSet ds = new DataSet();
                      Helper.ConnectionString = "Data Source=.\\\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Coupon Management.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                      //  SqlCommand txtcmd = new SqlCommand();
                        //  commandText ="'"+txtAmount .AutoPostBack +"'";
                      
                          string query = "select CouponName from CouponType";
                        ds = Helper.ExecuteDataSet(CommandType.Text, query, null);
                      
                        if (!IsPostBack)
                        {
                            ddlCType.DataSource = ds;
                            ddlCType.DataValueField = "CouponName";
                            ddlCType.DataTextField = "CouponName";
                            ddlCType.DataSourceID = String.Empty;
                        }
                      }
                      
                      protected DataSet GetData(string sqlCommand)
                      {
                      
                         da1  = new SqlDataAdapter(sqlCommand, cnx );
                         ds  = new DataSet();
                         da1.Fill(ds );
                          return ds ;
                      
                      }
                      

                      protected void DropDownList1_TextChanged(object sender, EventArgs e)
                      {
                      cnx.Open();
                      SqlCommand ddlcmd = new SqlCommand();
                      commandText = "SELECT MAX(CouponTransaction.SerialEnd),CouponType.Price FROM CouponType INNER JOIN CouponTransaction ON CouponType.CouponTypeID = CouponTransaction.CouponTypeID WHERE CouponType.CouponName= '" + ddlCType.SelectedValue + "'GROUP BY CouponType.Price";
                      ds = new DataSet();
                      ds = GetData(commandText);
                      if (ds.Tables[0].Rows.Count!=0 )
                      {
                      txtSFrom.Text = ds.Tables[0].Rows[0][0].ToString();
                      Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
                      cnx.Close();
                      }
                      }

                      M Offline
                      M Offline
                      mylogics
                      wrote on last edited by
                      #10

                      thanks .... ;)

                      1 Reply Last reply
                      0
                      • M mylogics

                        its not workin yet...

                        P Offline
                        P Offline
                        padmanabhan N
                        wrote on last edited by
                        #11

                        your code seems to be fine.... jus check whether u have values in the database...... :)

                        Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups