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. Dropdown pre-filled from prior page fires off required validator

Dropdown pre-filled from prior page fires off required validator

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netoraclesalesquestion
6 Posts 2 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.
  • B Offline
    B Offline
    Bootzilla33
    wrote on last edited by
    #1

    I have a dropdown(code is name of the dropdown) that when coming from another page it prefills with a value, the required validator fires off. I have a select statement that fills in all textboxes and dropdowns on this page. When I open this page by itself the validation functions as normal meaning when I select a value from the dropdown no validation and when it is blank it validates. Here is the code for the select statement and reading in the data on page load:

    OracleConnection conn = new OracleConnection();
    OracleCommand cmd = new OracleCommand();
    conn.ConnectionString = strConnection;
    conn.Open();

            cmd.Connection = conn;
            cmd.CommandText = "Select RID, CODE, CUSTOMER\_NAME from ACTIVITY WHERE ID = :IDValue";
            //Add values to paramter
            cmd.Parameters.Add(new OracleParameter("IDValue", Request.QueryString\["ID"\]));
    
            OracleDataAdapter da = new OracleDataAdapter(cmd);
            cmd.CommandType = CommandType.Text;
            OracleDataReader dr = cmd.ExecuteReader();
    
            name.Text = dr\["customer\_name"\].ToString();
            code.SelectedItem.Text = dr\["code"\].ToString();
    
            dr.Close();
            conn.Close();
    

    I know this has Oracle code in it but it is more of a C#/ASP.net question.

    Richard DeemingR 1 Reply Last reply
    0
    • B Bootzilla33

      I have a dropdown(code is name of the dropdown) that when coming from another page it prefills with a value, the required validator fires off. I have a select statement that fills in all textboxes and dropdowns on this page. When I open this page by itself the validation functions as normal meaning when I select a value from the dropdown no validation and when it is blank it validates. Here is the code for the select statement and reading in the data on page load:

      OracleConnection conn = new OracleConnection();
      OracleCommand cmd = new OracleCommand();
      conn.ConnectionString = strConnection;
      conn.Open();

              cmd.Connection = conn;
              cmd.CommandText = "Select RID, CODE, CUSTOMER\_NAME from ACTIVITY WHERE ID = :IDValue";
              //Add values to paramter
              cmd.Parameters.Add(new OracleParameter("IDValue", Request.QueryString\["ID"\]));
      
              OracleDataAdapter da = new OracleDataAdapter(cmd);
              cmd.CommandType = CommandType.Text;
              OracleDataReader dr = cmd.ExecuteReader();
      
              name.Text = dr\["customer\_name"\].ToString();
              code.SelectedItem.Text = dr\["code"\].ToString();
      
              dr.Close();
              conn.Close();
      

      I know this has Oracle code in it but it is more of a C#/ASP.net question.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Bootzilla33 wrote:

      code.SelectedItem.Text = dr["code"].ToString();

      Why are you changing the text of the selected item, rather than selecting the item? Try:

      code.SelectedValue = dr["code"].ToString();


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      B 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Bootzilla33 wrote:

        code.SelectedItem.Text = dr["code"].ToString();

        Why are you changing the text of the selected item, rather than selecting the item? Try:

        code.SelectedValue = dr["code"].ToString();


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        B Offline
        B Offline
        Bootzilla33
        wrote on last edited by
        #3

        I'm not changing the text?? I'm calling that value for that dropdown from the database by using the Select statement.

        Richard DeemingR 1 Reply Last reply
        0
        • B Bootzilla33

          I'm not changing the text?? I'm calling that value for that dropdown from the database by using the Select statement.

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Bootzilla33 wrote:

          code.SelectedItem.Text = dr["code"].ToString();

          That changes the text of the selected item. If you want to select a different item, use the SelectedValue property.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          B 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Bootzilla33 wrote:

            code.SelectedItem.Text = dr["code"].ToString();

            That changes the text of the selected item. If you want to select a different item, use the SelectedValue property.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            B Offline
            B Offline
            Bootzilla33
            wrote on last edited by
            #5

            Would that fix my original issue of the validator message popping up even though there is something in the field when coming from a prior page? If that fixes it or you think it fixes it then I will try it.

            Richard DeemingR 1 Reply Last reply
            0
            • B Bootzilla33

              Would that fix my original issue of the validator message popping up even though there is something in the field when coming from a prior page? If that fixes it or you think it fixes it then I will try it.

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Yes, I'm pretty sure that will fix it. Your current code is changing the text of the selected item, which probably doesn't have a value. NB: You could have tried it for yourself and found the answer immediately, rather than waiting over the weekend for my "permission" to try it. :)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              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