user3107231
user3107231

Reputation: 1

How to display multiple image in another page in C# asp.net

This is my C# codes for my Resort webpage. The problem is I can't display the image multiple times. It maybe possible for a single image. But after that, it does not work again. Please help me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Resorts : System.Web.UI.Page{

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == 1)
        {
            Session["room"] = "Deluxe Room";
            Label1.Text = "Classy Room";
            Label2.Text = "Good for you";
            Label3.Text = "100";

            Session["rom"] = Session["rom"]+"<br>"+ DropDownList1.Text;
            Session["prc"] = Session["prc"]+"<br>"+ Label3.Text;
            Session["img"] = Session["img"]+"<br>"+ Image1.Imageurl;
        }
        else if (DropDownList1.SelectedIndex == 2)
        {

            Session["room"] = "Deluxe Room";
            Label1.Text = "Nga-nga kayo";
            Label2.Text = "Good for me";
            Label3.Text = "100,000";

            Session["rom"] = Session["rom"]+"<br>"+ DropDownList1.Text;
            Session["prc"] = Session["prc"]+"<br>"+ Label3.Text;
            Session["img"] = Session["img"]+"<br>"+ Image1.Imageurl;

        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Biodata.aspx");
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == 1)
        {
            Button1.Enabled = true;
            Image1.ImageUrl = "~/Styles/Rooms/deluxe1.jpg";

            Label1.Text = "";
            Label2.Text = "";
            Label3.Text = "";
        }
        else if (DropDownList1.SelectedIndex == 2)
        {
            Button1.Enabled = true;
            Image1.ImageUrl = "~/Styles/Rooms/room2.jpg";

            Label1.Text = "";
            Label2.Text = "";
            Label3.Text = "";
        }
        else
        {
            Label1.Text = "";
            Label2.Text = "";
            Label3.Text = "";

            Image1.ImageUrl = "~/Styles/hand.jpg";
            Button1.Enabled = false;
        }
    }
}

The code I used for the image ( Session["img"] = Session["img"]+"<br>"+ Image1.Imageurl; )

This is the page where I want it to display.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Biodata : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Session["name"].ToString();
        TextBox2.Text = Session["adr"].ToString();
        TextBox3.Text = Session["con"].ToString();
        TextBox4.Text = Session["email"].ToString();

        Label1.Text = Session["rom"].ToString();
        Label5.Text = Session["prc"].ToString();
        Label4.Text = Session["room"].ToString();
    }
}

Upvotes: 0

Views: 1883

Answers (1)

Bhavesh Kachhadiya
Bhavesh Kachhadiya

Reputation: 3962

Try this code on other page.

protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Session["name"].ToString();
        TextBox2.Text = Session["adr"].ToString();
        TextBox3.Text = Session["con"].ToString();
        TextBox4.Text = Session["email"].ToString();


        Label1.Text = Session["rom"].ToString();
        Label5.Text = Session["prc"].ToString();
        Label4.Text = Session["room"].ToString();

        string strImageUrls = Convert.ToString(Session["img"]);
        string[] arrImageUrls = strImageUrls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        if (arrImageUrls != null && arrImageUrls.Length > 0)
        {
            foreach (string strImageURL in arrImageUrls)
            {
                //DO your image binding here like
                //Image1.ImageUrl = strImageURL ;
            }
        }
    }

Make changes in your button click event like this:

 protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == 1)
        {
            Session["room"] = "Deluxe Room";
            Label1.Text = "Classy Room";
            Label2.Text = "Good for you";
            Label3.Text = "100";

            Session["rom"] = Session["rom"] + "<br>" + DropDownList1.Text;
            Session["prc"] = Session["prc"] + "<br>" + Label3.Text;
            Session["img"] = Convert.ToString(Session["img"]) +  Image1.Imageurl + ",";
        }
        else if (DropDownList1.SelectedIndex == 2)
        {

            Session["room"] = "Deluxe Room";
            Label1.Text = "Nga-nga kayo";
            Label2.Text = "Good for me";
            Label3.Text = "100,000";

            Session["rom"] = Session["rom"] + "<br>" + DropDownList1.Text;
            Session["prc"] = Session["prc"] + "<br>" + Label3.Text;
            Session["img"] = Convert.ToString(Session["img"]) + Image1.Imageurl + ",";

        }
    }

Upvotes: 1

Related Questions