我試圖填充下拉列表控件。 '輸入'是數據庫。表是'ApplicationName',它有一個賦值給它的隨機值。SQL值不填充ASP DropDownList控件
出於某種原因,當我單擊「測試提交」按鈕時,控件中沒有任何內容出現(DropDownList1)。
protected void TestSubmit_ServerClick(object sender, EventArgs e)
{
// Initialize the database connector.
SqlConnection connectSQL = new SqlConnection();
// Send the connection string.
connectSQL.ConnectionString = @"Data Source = localhost\SQLEXPRESS;" +
"Initial Catalog = Inputs; Integrated Security = SSPI";
try
{
// Setup our command.
SqlCommand theCommand = new SqlCommand("SELECT * FROM Inputs", connectSQL);
// Write the stored value in the text boxes.
connectSQL.Open();
SqlDataReader theReader;
theReader = theCommand.ExecuteReader();
theReader.Read();
DropDownList1.Items.Add(theReader["ApplicationName"].ToString());
theReader.Close();
connectSQL.Close();
}
catch (Exception ee)
{
MessageBox("Oopsie: " + ee);
}
如果我有一行但多列,並且每列將填充下拉列表,該怎麼辦?我的問題在這裏:http://stackoverflow.com/questions/30310610/how-to-split-sql-query-result-to-populate-a-dropdownlist – SearchForKnowledge 2015-05-18 18:43:56