我怎样下拉列表重定向,而不​​是一个按钮? [英] How do I redirect with a Drop Down List, and not a Button?

查看:86
本文介绍了我怎样下拉列表重定向,而不​​是一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待到只使用一个DDL运行我的查询,而不是一个DDL和Button_Click功能。我还没有找到该怎么做。我该怎么做呢?

I am looking into using only a ddl to run my query, not a ddl and a Button_Click function. I am yet to find what to do. How do I do this?

推荐答案

在您为(P / C)X:

In your as(p/c)x:

<asp:DropDownList runat="server" 
                  id="ddl"
                  OnSelectedIndexChanged="SelectionChanged"
                  AutoPostBack="true">
    <asp:ListItem Text="Page 1" Value="/page1.aspx" />
    <asp:ListItem Text="Page 2" Value="/page2.aspx" />
</asp:DropDownList>

在的AutoPostBack属性告诉ASP.NET要连接,一旦提交表单的下拉列表更改客户端(JavaScript)的命令,而不是等待按下按钮。

The "AutoPostBack" property tells ASP.NET to wire up a client-side (javascript) command that submits the form as soon as the drop down list changes, instead of waiting for a button click.

而在你的codebehind,事件处理程序,我们在OnSelectedIndexChanged属性​​将被解雇引用的:

And in your codebehind, the event handler we referenced in the "OnSelectedIndexChanged" property will get fired:

protected void SelectionChanged(object sender, EventArgs e)
{
    Response.Redirect(((DropDownList)sender).SelectedValue);
}

这篇关于我怎样下拉列表重定向,而不​​是一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆