asp.net webcontrols:
I know this topic has probably been talked about to death...however I'm
having a problem with my dependent dropdownlists in the edittemplates within
a detailsview. I am trying to databind my dropdownlists once the selected
index has changed of the first dropdownlist has changed. The update of the
other dropdownlist works nicely, however, when I click update, I get the
following error:
"Cannot insert the value NULL into column 'dply_team_mbr_id', table
'25_Dev.dbo.EQP_ASGN'; column does not allow nulls. UPDATE fails.
The statement has been terminated."
From the error it appears the value of the dropdownlist is not being
translated to the field value of dply_team_mbr_id. How do I bind the
dropdownlist to that value? Thanks!
Here is my code:
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
Label lbl = DetailsView1.FindControl("LblFirstHide") as Label;
Label lblFirst = DetailsView1.FindControl("Label5") as Label;
Label lblLast = DetailsView1.FindControl("Label6") as Label;
DropDownList ddlTeam = DetailsView1.FindControl("ddlTeamID") as
DropDownList;
lbl.Text = ((DropDownList)sender).SelectedValue;
//SQL Connection string connects to 25_Dev
SqlConnection objCon = new SqlConnection("Data
Source=SQLTES;Initial Catalog=25_Dev;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("SELECT [empid],
[FirstName], [LastName] FROM [EMPLOYEES] WHERE empid='"+lbl.Text+"'", objCon);
DataSet ds = new DataSet();
da.Fill(ds);
//update first and last name in edititemtemplate of detailsview
lblFirst.Text = ds.Tables[0].Rows[0]["FirstName"].ToString();
lblLast.Text = ds.Tables[0].Rows[0]["LastName"].ToString();
SqlDataAdapter dB = new SqlDataAdapter("SELECT
DPLY_TEAM_MBR.dply_id, DPLY_TEAM_MBR.dply_team_mbr_id, DPLY_TEAM_MBR.empid,
DPLY.dply_team_name FROM DPLY_TEAM_MBR INNER JOIN DPLY ON
DPLY_TEAM_MBR.dply_id = DPLY.dply_id WHERE DPLY_TEAM_MBR.empid = '" +
lbl.Text + "'", objCon);
DataSet dsB = new DataSet();
dB.Fill(dsB);
ddlTeam.DataSource = dsB.Tables[0].DefaultView;
ddlTeam.DataTextField = "dply_team_name";
ddlTeam.DataValueField = "dply_team_mbr_id";
ddlTeam.DataBind();