2012-07-17 26 views
0

我有一些文本框。用戶需要在文本框中輸入數據。完成後,他們將點擊提交按鈕。然後,它將被引導至「review.aspx」頁面。在review.aspx頁面中,頁面將顯示標籤中前一頁插入的數據。這裏的任何人都知道如何去做?謝謝。如何在其他頁面顯示數據的會話

這是我停止

protected void Button2_Click(object sender, EventArgs e) 
{ 
    Session["brand"] = DropDownList1.SelectedItem.Text; 
    Session["model"] = TextBox1.Text; 
    Session["plate"] = TextBox2.Text; 
    Session["color"] = TextBox3.Text; 
    Session["year"] = TextBox4.Text; 
    Session["service"] = TextBox5.Text; 

    Response.Redirect "Review.aspx"; 

如何捕捉到會議回顧頁面顯示。我用標籤來顯示它。

回答

1

轉換會話[ 「ID」]對象爲字符串方式如下:

string brand=Session["brand"].ToString(); 
    string model=Session["model"].ToString(); 
    string plate=Session["plate"].ToString(); 
    string color=Session["color"].ToString(); 
    string year=Session["year"].ToString(); 
    string service=Session["service"].ToString(); 

,並在設定值各自的標籤:

lblBrand.Text=brand; 
lblModel.Text=model; 
lblPlate.Text=plate; 
lblColor.Text=color; 
lblYear.Text=year; 
lblService.Text=service; 
+0

謝謝!你是最棒的! – aemy 2012-07-17 05:51:49

1

會話數據類型是對象,我們必須將其轉換爲字符串類型,以便我們可以將其存儲在字符串變量中。

string brand = Session["brand"].ToString(); 
string model =(string) Session["model"]; 
string plate =(string) Session["plate"]; 
string color =(string) Session["color"]; 
string year =(string) Session["year"]; 
string service =(string) Session["service"]; 

設置標籤的文本屬性等於這些變量

Label1.Text = brand+""+model+""+plate+""+year+""+service; 
1

如何使用會話(樣品初學者)

步驟1,顯示其他頁面上的數據:吃兩web表單WebForm1的& webform2。

第二步:將一個texbox &一個按鈕WebForm1的&寫在按鈕下面的代碼單擊事件 -

Session["name"] = TextBox1.Text; 

Response.Redirect("webform2.aspx"); 

第三步:在webform2 &拖動標籤寫的頁面加載事件下面的代碼這個頁面(即:webform2)。

Label1.Text = Session["name"].ToString(); 

結論:輸入到webform1文本框中的名稱/數據將顯示在下一頁。

相關問題