Reputation: 2823
OK so i am a bit lost and could do with some help.
I am creating a program that a user inputs data into a form on the default page (I have that working).
Then i use session variables to get the data input from a text box on the default page and place that data into a drop down menu on Page2 (I have that working).
What im trying to do now is use the data selected from the drop down on the page2 and output it on to a label. any help would be appreciated.
Page2 code bellow session that populates drop down
public partial class About : Page
{
protected void Page_Load(object sender, EventArgs e)
{
MyFruit = Session["Fruitname"] as List<string>;
//Create new, if null
if (MyFruit == null)
MyFruit = new List<string>();
DropDownList1.DataSource = MyFruit;
DropDownList1.DataBind();
}
Upvotes: 0
Views: 6033
Reputation: 154
Not sure if this is what you are looking for but what I am guessing is you want an event for your drop down list to get the info and place it into a session to pass onto the next page
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string item=DropDownList.SelectedItem;
Session["selectedItem"]=item;
Response.Redirect("TheNextPageURL")
}
public partial class TheNextPage : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Session["selectedItem"]!=null)
{
Label1.Text=Session["selectedItem"].toString();
}
}
}
Hope that helps
Upvotes: 1
Reputation: 26209
You can use SelectedIndexChanged
event of DropDownList
to handle this.
your AutoPostBack
property of DropDownBox
should be set to True
sample code as below:
Design code: page.aspx
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>name1</asp:ListItem>
<asp:ListItem>name2</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
CodeBehind File: page.aspx.cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedValue.ToString();
}
Upvotes: 2