首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C# asp.net的另一页中显示多幅图像

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

Stack Overflow用户
提问于 2013-12-16 20:27:24
回答 1查看 1.7K关注 0票数 0

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

代码语言:javascript
复制
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; )的代码

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

代码语言:javascript
复制
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();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2013-12-16 20:38:56

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

代码语言:javascript
复制
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 ;
            }
        }
    }

在按钮单击事件中进行如下更改:

代码语言:javascript
复制
 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 + ",";

        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20610964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档