I have a DropdownList
Based on the selected text I populate another ddl with
protected void ddlComponentaActivitate_SelectedIndexChanged(Object sender, EventArgs e)
{
ddlFactorRisc.Items.Clear();
ddlFactorRisc.Items.Add("Factor de risc");
using (SqlConnection conn = new SqlConnection(connString))
{
string sqlQuery = "SELECT FactorRisc, FRFID FROM tblFactoriRiscFactori WHERE FRCID = @FRCID ORDER BY FactorRisc";
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@FRCID", ddlComponentaActivitate.SelectedItem.Value);
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlFactorRisc.DataSource = ds.Tables[0];
ddlFactorRisc.DataBind();
conn.Close();
}
}
ActiveTAB.Value = "#TabEvaluare";
}
The second ddl on View with
But when I try to add data to table using FactorRisc as parameter
cmd.Parameters.AddWithValue("@FactorRisc", ddlFactorRisc.SelectedItem.Text);
I have error that say cannot add null. So it seems it will not get the value. Worth to mention I have 2 more ddl on page, one listed below
On screen data is visible but error on postback. Why?

Marius VasilePosted Jun 16, 2024, 6:22 PM
I tried to store the values with jquery and it works
but why not directly from ddl with