Tag: selectedindexchanged

下拉OnSelectedIndexChanged没有触发

我的下拉框中没有触发OnSelectedIndexChanged事件。 我看过的所有论坛都告诉我添加AutoPostBack=”true” ,但这并没有改变结果。 HTML: 代码背后: public partial class _Default : Page { string _sLocation = string.Empty; string _sCurrentLoc = string.Empty; TimeSpan _tsSelectedTime; protected void Page_Load(object sender, EventArgs e) { AddTimeZones(); cboSelectedLocation.Focus(); lblCurrent.Text = “Currently in ” + _sCurrentLoc + Environment.NewLine + DateTime.Now; lblSelectedTime.Text = _sLocation + “:” + Environment.NewLine + DateTime.UtcNow.Add(_tsSelectedTime); } //adds all timezone […]

识别CheckedListBox项已被选中

我从来没有处理过checkedListBox1。 我想要制作的程序将受益于使用它而不必使用多个复选框。 我有代码: private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { int selected = checkedListBox1.SelectedIndex; this.Text = checkedListBox1.Items[selected].ToString(); } 这个问题是每次我点击框并突出显示,然后选择突出显示的对象。 我正在寻找的是识别所选内容的变化,而不是突出显示。 我还想知道的是,如果检查CheckListBox中的第一个索引项以及第三个索引项,我将如何检查它是否为真? 我确信我最终会弄明白,但看到代码会非常有帮助。 假设我有3个盒子:盒子A = messageBox.Show(“a”); 方框B = messageBox.Show(“b”); 方框C = messageBox.Show(“c”); 如果选中此框,它将仅显示mbox。 我想知道的是我如何检查它是否检查,例如,A和C是否被检查,以便如果我按下一个按钮,两个messageBoxes将显示“a”然后“c”

“SelectedIndexChanged”在ListBox中的“Items.Clear()”之后没有触发

对于ListBox(选择模式设置为One),我希望跟踪是否选择了所选项目。 为此,我向SelectedIndexChanged订阅了一个方法,并检查SelectedIndex是否为-1。 但是,我注意到在调用Items.Clear()之后事件不会触发,即使SelectedIndex更改为-1(如果它还不是-1)。 为什么不开火呢? 我知道我可以通过在清除列表之前为SelectedIndex分配-1来解决这个问题。 但有更好的方法吗? 这是一个复制它的简单代码: using System; using System.Windows.Forms; namespace ns { class Program { static ListBox lst = new ListBox(); public static void Main() { lst.SelectedIndexChanged += new EventHandler(lst_SelectedIndexChanged); lst.Items.Add(1); Console.WriteLine(“Setting selected index to 0…”); lst.SelectedIndex = 0; //event fire here Console.WriteLine(“(Selected Index == {0})”, lst.SelectedIndex); Console.WriteLine(“Clearing all items…”); lst.Items.Clear(); //event *should* […]

使用DataGridView Combobox的SelectionChangeCommitted Event获取新值或索引

我使用SelectionChangeCommitted在combobox选择的索引发生变化时捕获事件,但我无法获得它的新值或索引。 private void ruleList_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control is ComboBox) { ComboBox comboBox = e.Control as ComboBox; comboBox.SelectionChangeCommitted += ruleListColumnComboSelectionChanged; } } private void ruleListColumnComboSelectionChanged(object sender, EventArgs e) { string value = ruleList.CurrentCell.Value.ToString(); // just return the old value before the change }

SelectedIndexChanged不起作用!

我的代码: *的.aspx: * .aspx.cs: protected void Page_Load(object sender, EventArgs e) { CountryList.SelectedIndexChanged += new EventHandler(CountryList_SelectedIndexChanged); … } protected void CountryList_SelectedIndexChanged(object sender, EventArgs e) { LoadCityList(CountryList, CityList); } 但这不起作用。

ASP.NET / C#:DropDownList在服务器控件中没有触发的SelectedIndexChanged

我正在创建一个服务器控件,基本上绑定两个下拉列表,一个用于国家,一个用于州,并更新国家/地区的selectedindexchanged事件的状态下拉列表。 但是,它没有回发。 有什么想法吗? 将它们包装在UpdatePanel中的加分点(有渲染问题;也许是因为我没有要引用的页面?) 这就是我所拥有的(一些额外的数据访问内容被删除): public class StateProv : WebControl { public string SelectedCountry; public string SelectedState; private DropDownList ddlCountries = new DropDownList(); private DropDownList ddlStates = new DropDownList(); protected override void OnLoad(EventArgs e) { base.OnLoad(e); IList countries = GetCountryList(); IList states = new List(); if (SelectedCountry != null && SelectedCountry != “”) { states […]