如何将所选值从下拉菜单传递到下一页的另一个下拉菜单 [英] how to pass selected value from dropdown to another dropdown in next page

查看:100
本文介绍了如何将所选值从下拉菜单传递到下一页的另一个下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表单,当用户从下拉菜单中选择值时,它可以将它们定向到另一个页面.但是在下一页中,我希望将所选值传递给另一个下拉列表.

例如:用户选择国家/地区;然后直接转到下一个页面,其中已经有一个下拉菜单选择了国家/地区值.那么只有他们才能进行下一个过程...

注意:(下拉列表中的列表项与第一个列表相同)

希望任何人都能帮助我.

解决方案

使用会话将所选值传递到下一页.

然后在第二页上

 受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
    {
  ListBox2.Text =<调用会话值>
    } 


有很多方法可以将值从一页传递到另一页

其中一些对您有用.
QueryString
会话


这里是一种解决方案:
在第一个DropDownList 中将AutoPostBack 设置为true,然后在其SelectedIndexChanged 事件处理程序中写入:

会话[" ] = DropDownList1.SelectedIndex;  

在第二页OnLoad 事件处理程序中,编写以下代码:

 如果(会话["  lastSelectedCountryIndex"]!= " ]).ToString()); 



ASP.NET中还有一些其他状态管理选项,可以在这里找到:
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx [ ^ ]

希望对您有所帮助.


Hi,

i have a form when user select value from dropdown it can direct them to another page.but in the next page i want the selected value to be pass to another dropdown.

for instance: user select country;then go straight to next page where there is a dropdown already selected the country value. then only they can do the next process...

note:(listitem in dropdown is same with the 1st)

hope anyone can help me.

thanks.

解决方案

Pass the selected value to the next page using session.

then on the second page

protected void Page_Load(object sender, EventArgs e)
    {
  ListBox2.Text = <call the session value>
    }


Their are many ways to pass the values from one page to another page

Some of them are useful to you.
QueryString
Session


Here is one solution :
Set the AutoPostBack to true in first DropDownList then write in its SelectedIndexChanged event handler :

Session["lastSelectedCountryIndex"] = DropDownList1.SelectedIndex;



In the second page OnLoad event handler write this code :

if (Session["lastSelectedCountryIndex"]!=null)
    DropDownList2.SelectedIndex = Convert.ToInt32((Session["lastSelectedCountryIndex"]).ToString());



There are some other state management options in ASP.NET which can be found here :
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx[^]

Hope it helps.


这篇关于如何将所选值从下拉菜单传递到下一页的另一个下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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