我在收到错误时SelctedIndexChanged,当值改变时,他给出了我之前选择的值而不是新选择的值.
这有什么问题.
它们之间有什么区别
DropDownList.SelectedItem.Value
DropDownList.SelectedValue
Run Code Online (Sandbox Code Playgroud) 我有一个 HTML 控件:
<select id="grade">
Run Code Online (Sandbox Code Playgroud)
我想在选定的索引更改事件上获取下拉列表的选定值。
我尝试添加以下代码,这些代码将在下拉选择更改时调用,但似乎不起作用。还有其他建议吗?
$("#grade").on('change', function() {
alert("hi");
});
Run Code Online (Sandbox Code Playgroud)
另外,如何在 Java Script 中获取选定的值。
javascript events select selectedindexchanged drop-down-menu
我正在动态创建多个下拉列表(每个都有唯一的ID)并将它们绑定到面板.我还为它们编写了SelectedIndexChanged代码,每次更改下拉列表时都会触发它.我的问题是因为只有一个SelectedIndexChanged事件,我需要获取更改的下拉列表的ID.我怎么能得到它?
这是我将下拉列表绑定到面板的代码:
foreach (Document offer in parent.Children)
{
Panel pnlCat = new Panel();
pnlCat.ID = offer.Id.ToString();
pnlCat.CssClass = "ngx";
DropDownList ddl = new DropDownList();
ddl.ID = offer.Id + "_cat";
ddl.DataTextField = "catName";
ddl.DataValueField = "catId";
ddl.CssClass = "ddlStyle";
ddl.DataSource = category;
ddl.DataBind();
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
pnlCat.Controls.Add(ddl);
}
Run Code Online (Sandbox Code Playgroud)
这是SelectedIndexChanged代码:
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string id = this.ClientID;
}
Run Code Online (Sandbox Code Playgroud)
在id我得到"_page".我怎样才能获得下拉列表ID?
我在我的 C# 应用程序中创建一个名为 Acquisti 的类。然后我在表单构造函数中初始化它,然后在组合框 SelectedIndexChanged 事件中调用此类的方法。问题是,当我运行该程序时,出现错误,指出我创建的 Acquisti 类的对象为 null。这意味着 SelectedIndexChanged 事件在表单构造函数之前调用,不是吗?我也尝试过 SelectedValueChanged 事件,但我遇到了同样的问题。这是简单的代码:
Acquisti _acquisti;
public Form1()
{
InitializeComponent();
WindowState = FormWindowState.Maximized;
for (int i = DateTime.Now.Year; i >= 2000; i--)
annoAcquisti.Items.Add(i);
annoAcquisti.SelectedIndex = 0;
_acquisti = new Acquisti();
}
private void annoAcquisti_SelectedIndexChanged(object sender, EventArgs e)
{
_acquisti.load(ref acquistiDGV, annoAcquisti.SelectedItem.ToString());
}
Run Code Online (Sandbox Code Playgroud) 我有一个绑定到 BindingList 的 ListBox,默认情况下该 ListBox 为空。
当选定的索引更改时,它应该使用选定对象中的数据更新其他控件。
问题是 SelectedIndexChanged 事件不会在第一个条目上触发(索引从 -1 更改为 0)。
但是,当我再次单击第一个条目(尽管在这种情况下索引没有改变)以及添加更多条目时,它确实会触发。
我检查了 myListBox.SelectedIndex 属性,它实际上从 -1 更改为 0,但由于某种原因没有调用事件处理程序。有谁知道为什么这样做以及如何解决它?
这是我的代码:
public partial class main : Form
{
// The class of objects in my BindingList
[Serializable]
public class DisplayDefinition : INotifyPropertyChanged
{
private string _name;
private int _width, _height, _posx, _posy;
public string Name { get { return _name; } set { _name = value; NotifyPropertyChanged("Name"); } }
public int Width { get { return _width; } set { …Run Code Online (Sandbox Code Playgroud) foreach(o.list中的书b){ListBox_Items.Items.Add(b.Title); }
执行此操作后,标题现在显示在列表框中.
当我进行选择(单一模式)时,ListBox_Items(屏幕)突出显示所选行,但事件SelectedIndexChanged未触发.
protected void ListBox_Items_SelectedIndexChanged(object sender, EventArgs e)
{
int i = ListBox_Items.SelectedIndex;
}
ID="ListBox_Items" runat="server" EnableViewState="False" Width="400px" Rows="25" onselectedindexchanged="ListBox_Items_SelectedIndexChanged"
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
迈克尔
编辑1:感谢大家的帮助.现在就开始工作了.无论如何,我也必须将EnableViewState打开为True.因为我有一个"删除"按钮来从列表框控件中删除项目,如果EnableViewState为False,每当我单击"删除"按钮时,列表框将再次变为空.
我注意到当我从gridview中的选定行填充文本框时,如果该字段为空,则在文本框中显示" ".
这是我提出的解决方案.我在检查每个单元格之前将其添加到文本框中.
我觉得我要么做错了,要么首先出现这个问题,要么就是有更好的方法来解决这个问题.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//// Get the currently selected row using the SelectedRow property.
GridViewRow row = GridView1.SelectedRow;
// Load data from selected row into textboxes
if (row.Cells[1].Text.Trim() != " ")
{
txtEditCust_ID.Text = row.Cells[1].Text.Trim();
}
}
Run Code Online (Sandbox Code Playgroud) win表格上有一个组合框和一个按钮.如何通过单击按钮来激活comboBox selectedIndexChanged.
我的目标是让我的按钮灵活,取决于我的组合框的当前值,但问题是当我在该特定事件上运行我的程序它冻结,我的语法有问题或我的电脑只是慢?
private void cmbOperation_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = (string)cmbOperation.SelectedItem;
while (selected == "ADD")
{
txtID.ReadOnly = true;
txtLName.ReadOnly = false;
txtFName.ReadOnly = false;
txtMI.ReadOnly = false;
txtGender.ReadOnly = false;
txtAge.ReadOnly = false;
txtContact.ReadOnly = false;
btnOperate.Text = "ADD CLIENT";
}
}
private void btnOperation_Clicked(object sender, EventArgs e)
{
if (cmbOperation.SelectedItem.Equals("ADD"))
{
string constring = "datasource=localhost;port3306;username=root";
string Query = "insert into mybusiness.client_list (LastName,FirstName,MI,Gender,Age,Contact) values('" + this.txtLName.Text + "','" + this.txtFName.Text + "','" + this.txtMI.Text + "','" + this.txtGender.Text …Run Code Online (Sandbox Code Playgroud)