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

レビューページに表示されるセッションをキャッチする方法。ラベルを使って表示しました。

4

3 に答える 3

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;
于 2012-07-17T05:22:11.430 に答える
1

次の方法でsession["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;
于 2012-07-17T05:24:43.120 に答える
1

セッションを使用して他のページにデータを表示する方法(初心者向けサンプル)

ステップ1:2つのWebフォームwebform1とwebform2を取得します。

step2:webform1にtexboxとボタンをドラッグし、ボタンクリックイベントに次のコードを記述します-

Session["name"] = TextBox1.Text;

Response.Redirect("webform2.aspx");

step3:webform2にラベルをドラッグし、このページのページ読み込みイベントに次のコードを記述します(例:webform2)。

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

結論:webform1のテキストボックスに入力された名前/データは次のページに表示されます。

于 2013-12-10T06:52:01.380 に答える