如何在C#asp.net中的另一个页面中显示多个图像

时间:2013-12-16 12:27:24

标签: c# asp.net

这是我的度假村网页的C#代码。问题是我无法多次显示图像。它可能是单个图像。但在那之后,它再也不起作用了。请帮帮我。

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;
        }
    }
}

我用于图片( Session["img"] = Session["img"]+"<br>"+ Image1.Imageurl; )

的代码

这是我希望它显示的页面。

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();
    }
}

1 个答案:

答案 0 :(得分:1)

在其他页面上试用此代码。

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 ;
            }
        }
    }

在按钮点击事件中进行更改,如下所示:

 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 + ",";

        }
    }