我的DropDownList有問題。在閱讀了很多帖子之後,我仍然無法讓它工作得如此糟糕。DropDownList只選擇第一個值
這是我的C#代碼:
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection("Data Source=PCM13812;Initial Catalog=Newsletter;Integrated Security=True"))
{
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("Select Email From Newsletter", connection);
EmailList.DataSource = cmd.ExecuteReader();
EmailList.DataTextField = "Email";
EmailList.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Vælg_Click(object sender, EventArgs e)
{
EmailListe .Text = EmailList.Text;
}
這裏是我的asp代碼:
<asp:DropDownList ID="EmailList" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:Button runat="server" ID="Vælg" Text="Vælg Email" OnClick="Vælg_Click" />
<asp:TextBox runat="server" ID="EmailListe" TextMode="MultiLine" />
<asp:TextBox ID="Besked" runat="server" />
正如你可以看到我從我SqlDatabase DropDownList的值。當我在下拉列表中選擇電子郵件並單擊該按鈕時,即使我選擇了另一個電子郵件,它也總是將第一個值添加到文本框中。
我在做什麼錯?
下一步...爲什麼downvote? –