Dropdown pre-filled from prior page fires off required validator
-
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.
-
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.
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
-
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
I'm not changing the text?? I'm calling that value for that dropdown from the database by using the Select statement.
-
I'm not changing the text?? I'm calling that value for that dropdown from the database by using the Select statement.
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
-
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
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.
-
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.
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