如何在DropDownList控件的下拉菜单中,选择一个项,点击后可以链接到另一个网页,该如何实现,初学的,麻烦指点一下!谢谢!
------解决方案--------------------------------------------------------
override protected void OnInit(EventArgs e)
{
//Add
this.DropDownList1.AutoPostBack =true;
}
private void InitializeComponent()
{
//Add
this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.Response.Redirect( "你要连接的Page ");
}
------解决方案--------------------------------------------------------
其实楼主想要的就是上面写的那个
switch (Dropdownlist1.SelectedValue)
{
case 1:
Response.redirect( "http://www.163.com ");
break;
case 2:
Response.redirect( "http://www.sina.com ");
break;
default:
Response.redirect( "http://www.163.com ");
break;
}
不过这里的1,2,3要注意
------解决方案--------------------------------------------------------
设置DropDownList1.AutoPostBack=true;
添加SelectedIndexChanged事件,代码如下
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged+=new System.EvenHandler(this.DropDownList1_SelectedIndexChanged);
}
1.如果是本网页跳转到其他网页,代码如下:
private DropDownList1_SelectedIndexChanged(object sender,System.EvenArgs e)
{
Response.Redirect( "newpage.aspx ");
}
2.如果要弹出一个新网页,代码如下:
private DropDownList1_SelectedIndexChanged(object sender,System.EvenArgs e)
{
Response.Write( " <script> window.open( 'newpage.aspx ') </script> ");
}
注:记事本情况写的,可能大小写等有错误