在线等候 ,多谢帮忙: DropDownList 下拉控件的问题
在<asp:DropDownList ID="w1" runat="server" AutoPostBack="true">
<asp:ListItem Value="http://www.163.com" >项目1</asp:ListItem>
<asp:ListItem Value="http://www.126.com">项目2</asp:ListItem>
<asp:ListItem Value="http://www.55.com">项目3</asp:ListItem>
</asp:DropDownList>
改下拉列表中点击相应的对象可以跳转到改对象所在的 链接,比如 点击 "项目1"挑转到 www.163.com.....
请问大侠怎么实现?
问题点数:20、回复次数:10Top
1 楼hyj_828(水梦)回复于 2006-01-04 14:35:13 得分 0
在onindexchanged事件裏面.調用Server.transer("www.163.com")Top
2 楼xwjss()回复于 2006-01-04 14:40:56 得分 10
aspx代码
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication4.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 136px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="http://www.163.com">项目1</asp:ListItem>
<asp:ListItem Value="http://www.126.com">项目2</asp:ListItem>
<asp:ListItem Value="http://www.55.com">项目3</asp:ListItem>
</asp:DropDownList></FONT>
</form>
</body>
</HTML>
cs代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication4
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Response.Redirect(DropDownList1.SelectedValue);
}
}
}
Top
3 楼blackhero(黑侠客)回复于 2006-01-04 14:42:06 得分 0
双击w1控件写
Response.Redirect(w1.selectitem.Value)Top
4 楼anheizhizi(目标:★★★★★)回复于 2006-01-04 14:44:52 得分 2
楼上写的方法,有没想过会出现这种情况 http://localhost/WebApplication1/www.163.com
Top
5 楼hyj_828(水梦)回复于 2006-01-04 14:47:37 得分 0
那就最好用window.open()就啥都不怕咯。Top
6 楼CnEve(龙哥哥)回复于 2006-01-04 14:52:43 得分 5
private void Page_Load(object sender, System.EventArgs e)
{
this.w1.Attributes.Add("onchange", "window.location=this.value");
}Top
7 楼CnEve(龙哥哥)回复于 2006-01-04 14:55:13 得分 0
结果:
<body>
<select onchange="window.location=this.value">
<option Value="http://www.163.com" >项目1</option >
<option Value="http://www.126.com">项目2</option >
<option Value="http://www.55.com">项目3</option >
</select>Top
8 楼zhangxiaopin(zxp)回复于 2006-01-04 15:05:50 得分 3
<script language="javascript">
<!--
function OpenWindowUrl()
{
var varurl="";
if(Form1.drpList.selectedIndex==1)
{
varurl=Form1.drpList.value;
window.location.href=varurl;
}
}
//-->
</script>
<select id="drpList" runat="server" onclick="OpenWindowUrl()">
<option selected></option>
<option value="http:\\www.svcar.com">Svcar</option>
</select>
Top
9 楼wgf2008(gaofeng)回复于 2006-01-04 15:20:24 得分 0
thanks a lot !Top
10 楼jijl2001(jijl2001)回复于 2006-01-04 15:24:13 得分 0
private void Page_Load(object sender, System.EventArgs e)
{
this.w1.Attributes.Add("onchange", "window.location=this.value");
}
龙哥哥的方法Top





