我有一個DropDownList
和方法OnSelectedIndexChanged
事件更改一個標籤的內容。除了DropDownList
的第一個元素外,它工作正常。有任何想法嗎?OnSelectedIndexChanged事件不會觸發DropDownList的第一個元素
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newsletter.DAL;
using Newsletter.Services;
public partial class Senders : System.Web.UI.Page
{
private SenderService _client;
private List<Sender> _allSenders;
private DropDownList _dropDownListSenders;
private TextBox _emailBox;
private string _selectedSender;
protected void Page_Load(object sender, EventArgs e)
{
_client = new SenderService();
_allSenders = _client.GetAllSenders();
_dropDownListSenders = (DropDownList)loginViewMain.FindControl("DropDownListSenders");
_emailBox = (TextBox)loginViewMain.FindControl("textBoxEmail");
}
protected void DropDownListSenders_SelectedIndexChanged(object sender, EventArgs e)
{
_selectedSender = _dropDownListSenders.SelectedValue;
_emailBox.Text = _selectedSender;
}
}
嘗試在DDL上將「AutoPostback」設置爲true。 – keyboardP
看到http://stackoverflow.com/questions/8699163/first-item-in-dropdownlist-doesnt-fire-selectedindexchanged-at-all –