【问题标题】:ASP.NET DropDownList - add get parameter to url after changing itemASP.NET DropDownList - 更改项目后将获取参数添加到 url
【发布时间】:2014-11-05 11:30:11
【问题描述】:

我在 asp.net webforms 中有下拉列表:

<asp:DropDownList runat="server" ID="ItemDate"  DataSourceID="dsItems" DataTextField="Name" DataValueField="Value" AutoPostBack="true" EnableViewState="true" >
                    </asp:DropDownList>

但是 url 还是一样的:

http://.../Default.aspx

我想改变这个url应该有附加参数的方法:

http://.../Default.aspx?item=23

【问题讨论】:

  • 我在给定的下拉列表和string item= Request.QueryString["Item"]; 之间找不到任何关系,您如何才能像这样在查询字符串中获取下拉列表的值。您传递的Item 是什么? >
  • 我纠正了这个错误
  • 嗯嗯..现在检查我的答案下面这是你如何处理它..

标签: c# asp.net webforms http-get


【解决方案1】:

你可以在这里使用 SelectedIndexChanged 事件将你的 DropDown 绑定到 aspx 中,如下所示。

 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
            OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
 </asp:DropDownList>

然后在C#代码后面使用下面的sn-p..

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{          
  Response.Redirect(Request.Url.AbsolutePath+"?item=" + DropDownList1.SelectedValue);
}

【讨论】:

  • 好的,但是现在回发是两次
  • 我同意你的观点.. javascript 可以帮助你.. 如果你完成了.. 否则我会告诉你..
猜你喜欢
  • 1970-01-01
  • 2016-07-20
  • 2014-03-21
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多