如何将项目从下拉列表发送到另一页上的文本框。 [英] How Do I Send A Item From A Drop Down List To A Textbox On Another Page.

查看:72
本文介绍了如何将项目从下拉列表发送到另一页上的文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这些控件发送值:



im sending values from these controls :

protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["Departure"] = ddDeparture;
            Session["Arrival"] = ddArrival;
            Session["DepartureCalendar"] = btnShowCalendar1.Text;
            Session["ArrivalCalendar"] = btnShowCalendar2.Text;
            Response.Redirect("Search.aspx");
        }





到这些:





to these:

protected void Button1_Click(object sender, EventArgs e)
        {
            txtDeparture.Text = (DropDownList)Session["Departure"];
            txtArrival.Text = (DropDownList)Session["Arrival"];
            txtDateOfDeparture.Text = (string)Session["DepartureCalendar"];
            txtDateOfArrival.Text = (string)Session["ArrivalCalendar"];  
        }





但我收到此错误:

无法转换类型为'System'的对象.Web.UI.WebControls.DropDownList'键入'System.String'。



我需要尽快帮助你。谢谢



but i get this error:
Unable to cast object of type 'System.Web.UI.WebControls.DropDownList' to type 'System.String'.

I NEED YOUR HELP ASAP. THANKS

推荐答案

您将整个下拉列表分配给下面提到的代码中的文本框

you are assigning whole dropdown list to text box in below mention code
txtDeparture.Text = (DropDownList)Session["Departure"];





像这样更改你的代码





Change your code like this

protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["Departure"] = ddDeparture.SelectedItem.Text;
            Session["Arrival"] = ddArrival.SelectedItem.Text;
             Session["DepartureCalendar"] = btnShowCalendar1.Text;
            Session["ArrivalCalendar"] = btnShowCalendar2.Text;
            Response.Redirect("Search.aspx");
        }






and

protected void Button1_Click(object sender, EventArgs e)
        {
            txtDeparture.Text = Convert.ToString(Session["Departure"]);
            txtArrival.Text = Convert.ToString(Session["Arrival"]);
            txtDateOfDeparture.Text = (string)Session["DepartureCalendar"];
            txtDateOfArrival.Text = (string)Session["ArrivalCalendar"];
        }


这篇关于如何将项目从下拉列表发送到另一页上的文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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