Need help populating fields from database to form in page load
-
I am trying to populate the fields on a form from the database and the values aren't populating on the form. I have the value for the where clause hard coded in the code and it doesn't show the values that are in the database for that record on the form:
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;{ labelRID.Text = Request.QueryString\["id"\]; string rid = labelRID.Text; string activityid = labelactivityid.Text; if (!IsPostBack) { Bindactivitycodedropdown(); if (rid != "") { OracleConnection conn = new OracleConnection(); OracleCommand cmd = new OracleCommand(); conn.ConnectionString = strConnection; conn.Open(); cmd.Connection = conn; cmd.CommandText = "Select RID, BUYING\_ACTIVITY\_ID, CUSTOMER\_SOURCE\_CODE, CUSTOMER\_NAME, CUSTOMER\_CITY, CUSTOMER\_STATE, CUSTOMER\_POSTAL\_CODE, BUYING\_ACTIVITY\_CODE from BUYING\_ACTIVITY WHERE RID = '55555'"; cmd.Parameters.Add(new OracleParameter("RID", Request.QueryString\["ID"\])); OracleDataAdapter da = new OracleDataAdapter(cmd); cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { labelRID.Text = dr\["rid"\].ToString(); custname.Text = dr\["customer\_name"\].ToString(); custcity.Text = dr\["customer\_city"\].ToString(); custstate.Text = dr\["customer\_state"\].ToString(); custpostalcode.Text = dr\["customer\_postal\_code"\].ToString(); activitycode.SelectedItem.Text = dr\["buying\_activity\_code"\].ToString(); custsrccode.Text = dr\["customer\_source\_code"\].ToString(); cvactivitycode.Enabled = false; //custname.Text = custstate.SelectedValue.ToString(); //if (activitycode.SelectedValue == "0") //{ // cu
-
I am trying to populate the fields on a form from the database and the values aren't populating on the form. I have the value for the where clause hard coded in the code and it doesn't show the values that are in the database for that record on the form:
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;{ labelRID.Text = Request.QueryString\["id"\]; string rid = labelRID.Text; string activityid = labelactivityid.Text; if (!IsPostBack) { Bindactivitycodedropdown(); if (rid != "") { OracleConnection conn = new OracleConnection(); OracleCommand cmd = new OracleCommand(); conn.ConnectionString = strConnection; conn.Open(); cmd.Connection = conn; cmd.CommandText = "Select RID, BUYING\_ACTIVITY\_ID, CUSTOMER\_SOURCE\_CODE, CUSTOMER\_NAME, CUSTOMER\_CITY, CUSTOMER\_STATE, CUSTOMER\_POSTAL\_CODE, BUYING\_ACTIVITY\_CODE from BUYING\_ACTIVITY WHERE RID = '55555'"; cmd.Parameters.Add(new OracleParameter("RID", Request.QueryString\["ID"\])); OracleDataAdapter da = new OracleDataAdapter(cmd); cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { labelRID.Text = dr\["rid"\].ToString(); custname.Text = dr\["customer\_name"\].ToString(); custcity.Text = dr\["customer\_city"\].ToString(); custstate.Text = dr\["customer\_state"\].ToString(); custpostalcode.Text = dr\["customer\_postal\_code"\].ToString(); activitycode.SelectedItem.Text = dr\["buying\_activity\_code"\].ToString(); custsrccode.Text = dr\["customer\_source\_code"\].ToString(); cvactivitycode.Enabled = false; //custname.Text = custstate.SelectedValue.ToString(); //if (activitycode.SelectedValue == "0") //{ // cu
Bootzilla33 wrote:
activitycode.SelectedItem.Text = dr["buying_activity_code"].ToString(); ... activitycode.SelectedItem.Text = "";
You're still changing the text of the first item in the list, rather than selecting the correct item. As I keep telling you, you need to set the
SelectedValue
property on the list, not theText
property on theSelectedItem
.activitycode.SelectedValue = dr["buying_activity_code"].ToString();
...
activitycode.SelectedValue = "";If the other values are not populating, then there is no matching record in the database. If you think there is, then you're not looking at the same database as your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer