基本上我製作了一個網頁表單,您可以在其中填寫所有文本框,然後從下拉菜單中選擇一個類別並點擊提交。根據你選擇的類別應該規定來自文本框的數據存儲在哪個字符串中。當涉及到C#和ASP.NET時,我處於新手級別,並且我的if語句有些問題,但我無法弄清楚如何正確地做到這一點。下面存儲一個基於字符串的下拉列表選擇
代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
string non_fiction;
string fiction;
string self_help;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Submit_btn_Click(object sender, EventArgs e)
{
if (Cat_DropDownList.SelectedIndex = 0)
{
fiction = "Title: " + Titletxt.Text + " | " + "Description: " + Descriptiontxt.Text + " | " + "Price: " + Pricetxt.Text + " | " + "Quantity: " + Quantitytxt.Text;
}
if (Cat_DropDownList.SelectedIndex = 1)
{
non_fiction = "Title: " + Titletxt.Text + " | " + "Description: " + Descriptiontxt.Text + " | " + "Price: " + Pricetxt.Text + " | " + "Quantity: " + Quantitytxt.Text;
}
if (Cat_DropDownList.SelectedIndex = 2)
{
self_help = "Title: " + Titletxt.Text + " | " + "Description: " + Descriptiontxt.Text + " | " + "Price: " + Pricetxt.Text + " | " + "Quantity: " + Quantitytxt.Text;
}
}
}
也才能拯救他人文章,我需要找出辦法把這些存儲的,所以我可以稱之爲「全面」的字符串,並將其添加到另一個頁面上的其他一個。
採用' ='而不是'=='在'if'條件下是一個語法錯誤。你沒注意到嗎? – Lion 2012-01-28 19:13:21