我想让我的DropDownList 每隔一秒index自动加一.
private void Button1_Click(object sender, System.EventArgs e)
{
wxyt w=new wxyt ();
Thread t=new Thread (new ThreadStart(w.bofang));
t.Start();
w.bofang();
} void bofang()
{
while(true)
{
//Thread.Sleep(1000);
this.DropDownList1.SelectedIndex+=1;
if(this.DropDownList1.SelectedIndex==23)
{
this.DropDownList1.SelectedIndex=0;
}
}
}
这样报错说是未处理的“System.NullReferenceException”类型的异常出现在 未知模块 中。其他信息: 未将对象引用设置到对象的实例。
大家帮帮忙,或者有没有更好的办法.this.DropDownList1.SelectedIndex+=1;会不会触发DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) 谢谢大家!!!!
private void Button1_Click(object sender, System.EventArgs e)
{
wxyt w=new wxyt ();
Thread t=new Thread (new ThreadStart(w.bofang));
t.Start();
w.bofang();
} void bofang()
{
while(true)
{
//Thread.Sleep(1000);
this.DropDownList1.SelectedIndex+=1;
if(this.DropDownList1.SelectedIndex==23)
{
this.DropDownList1.SelectedIndex=0;
}
}
}
这样报错说是未处理的“System.NullReferenceException”类型的异常出现在 未知模块 中。其他信息: 未将对象引用设置到对象的实例。
大家帮帮忙,或者有没有更好的办法.this.DropDownList1.SelectedIndex+=1;会不会触发DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) 谢谢大家!!!!
这句要加个判断,是否存在你加1后的索引项
if(this.DropDownList1.SelectedIndex==23) //这里也要注意是否超出索引
{
this.DropDownList1.SelectedIndex=0;
}
else
{
this.DropDownList1.SelectedIndex+=1;
}
var index=0;
function dropDownChange()
{
var drop=document.getElementById("DropDownList1");
// var showDiv=document.getElementById("showContent");
if(index==下拉列表的数量)
{
index=0;
}
else{
index++;
}
//showContent.innerText=showContent.innerText+" "+drop.options[index].value;
window.setInterval(dropDownChange,10000);
}
</script>