【发布时间】:2012-02-21 07:01:54
【问题描述】:
基本上,我正在制作一个网络表单,您将在其中填写所有文本框,然后从下拉列表中选择一个类别并点击提交。根据您选择的类别应该决定文本框中的数据存储在哪个字符串中。当涉及到 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条件中使用=而不是==是语法错误。你没注意到吗?
标签: c# asp.net if-statement store