P
Phil Streiff
I prototyped a data-entry webform w/ c# & inline aspx. After I got it
working, I tried to split my code out to a codebehind file (.cs) & now
my dropdownlist isn't populating with choices for the user to select.
Here's my code:
--------------------------------------------------
public void Page_Load (object sender, System.EventArgs e) {
if(!IsPostBack) {
SqlConnection myConn = new
SqlConnection(ConfigurationSettings.AppSettings["connString"]);
SqlCommand acctCmd = new SqlCommand("sp_Get_AccountType");
acctCmd.CommandType = CommandType.StoredProcedure;
myConn.Open();
SqlDataReader drAccount = acctCmd.ExecuteReader();
//Set up the data binding.
ddlAcctType.DataSource = drAccount;
ddlAcctType.DataTextField = "AccountType";
ddlAcctType.DataValueField = "AcctTypeID";
ddlAcctType.DataBind();
//Close the connection.
myConn.Close();
drAccount.Close();
//Add the item at the first position.
ddlAcctType.Items.Insert(0, "<---- Select ---->");
}
}
-----------------------------------------------------
here is aspx reference:
<aspropDownList id=ddlAcctType runat="server"
width="200px"></aspropDownList>
-----------------------------------------------------
The .aspx page now displays with no errors but the dropdownlist
appears empty. What am I doing wrong that's causing the ddl to not
populate in codebehind?
TIA,
Phil
working, I tried to split my code out to a codebehind file (.cs) & now
my dropdownlist isn't populating with choices for the user to select.
Here's my code:
--------------------------------------------------
public void Page_Load (object sender, System.EventArgs e) {
if(!IsPostBack) {
SqlConnection myConn = new
SqlConnection(ConfigurationSettings.AppSettings["connString"]);
SqlCommand acctCmd = new SqlCommand("sp_Get_AccountType");
acctCmd.CommandType = CommandType.StoredProcedure;
myConn.Open();
SqlDataReader drAccount = acctCmd.ExecuteReader();
//Set up the data binding.
ddlAcctType.DataSource = drAccount;
ddlAcctType.DataTextField = "AccountType";
ddlAcctType.DataValueField = "AcctTypeID";
ddlAcctType.DataBind();
//Close the connection.
myConn.Close();
drAccount.Close();
//Add the item at the first position.
ddlAcctType.Items.Insert(0, "<---- Select ---->");
}
}
-----------------------------------------------------
here is aspx reference:
<aspropDownList id=ddlAcctType runat="server"
width="200px"></aspropDownList>
-----------------------------------------------------
The .aspx page now displays with no errors but the dropdownlist
appears empty. What am I doing wrong that's causing the ddl to not
populate in codebehind?
TIA,
Phil