Ciao a tutti, ho un problema con l'elenco a discesa. Sto usando un elenco a discesa con origine dati. Come posso ottenere quel valore che ho selezionato?DropdownList DataSource
// I need a if statement here because my programme doesn't know which value of dropdown list selected and I don't know how to use this with datasource.
if(//if I select quiz 1 from dropdown list ,quiz 1 should list questions.)
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
string chooce = "Select Quiz from tblQuiz where Quiz=1 ";
SqlCommand userExist = new SqlCommand(chooce, con);
con.Open();
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
if (temp == 1)
{
if (rbList.Items[0].Selected == true)
{
string cmdStr = "Select Question from tblQuiz where ID=1";
SqlCommand quest = new SqlCommand(cmdStr, con);
lblque.Text = quest.ExecuteScalar().ToString();
con.Close();
}
Il codice che avete elencato in realtà non corrisponde alla domanda che hai chiesto. È necessario conoscere il nome/id dell'elenco a discesa, il tipo di origine dati utilizzato e il modo in cui è stata associata l'origine dati all'elenco a discesa per poter rispondere in modo efficace. – MadHenchbot