DropDownList跳转(做成友情链接)

来源:百度知道 编辑:UC知道 时间:2024/05/15 23:35:28
想用DropDownList做成友情链接,下拉菜单选到哪个就链接至相应的页面,我在ACCESS数据库中建立了表information_link,里面有属性值link_id(友情链接ID),link_name(链接网站名),link_website(链接网址),想实现DropDownList的下拉菜单从表中读取link_name,选中时,跳转至网址为相应的link_website的网页中,这个该怎么做哦?
我用vs2005做的,script language="JavaScript" Language="C#",用aspx的。
.aspx文件中加的DropDownList,设置AutoPostBack为True 后,我想知道在.cs文件中该怎么来写具体的代码,能否详细提供代码,我实在不会写,比如如何写Response.Redict(link_website),或者如何查出选中的value值,通过这个id去查询出数据库里对应的link_website值。
照着风吹过的沙漠提供的做法,还是出现以下错误,不知道该怎么改?
错误1:“System.Web.UI.WebControls.DropDownList”并不包含“SelectValue”的定义
错误2:当前上下文中不存在名称“link_id”、“link_name”、“dt”
错误3:“object”并不包含“toString”的定义
错误4:当前上下文中不存在名称“response”

1.
Page_Load()
{
if(!IsPostBack)
{
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = link_name;
DropDownList1.DataValueField = link_id;
DropDownList1.DataBind();
}
}
2.设置DropDownList1的AutoPostBack为True
3.双击DropDownList1在事件里写
{
DataRow[] dr = dt.select("link_id="+DropDownList1.SelectValue);
string sUrl = dr[0]["link_name"].toString()+"?link_id="+DropDownList1.SelectValue;
response.write("<script>window.open(surl)</script>")

}

首先设置DropDownList1的AutoPostBack为True
然后添加事件:
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectValue+"')</script>")
}

先设置DropDownList1的AutoP