主题:[讨论]有谁可以帮我改进一下我的代码呢~谢谢高手们
我做了一个关于很简单的早餐记录,~~~就是入门的那种。
以下是我的代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Please enter your name :<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>MR.</asp:ListItem>
<asp:ListItem>Miss.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
</asp:DropDownList><br />
<asp:TextBox ID="txtname1" runat="server" OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
<br />
<asp:TextBox ID="txtname2" runat="server"></asp:TextBox><br />
<br />
<br />
<br />
<br />
What would you like for breakfast :<br />
<br />
<asp:CheckBoxList ID="breakfastitem" runat="server" OnSelectedIndexChanged="breakfastitem_SelectedIndexChanged">
<asp:ListItem>Cereal</asp:ListItem>
<asp:ListItem>Eggs</asp:ListItem>
<asp:ListItem>Toast</asp:ListItem>
</asp:CheckBoxList><br />
<h4>
Feed me:
</h4>
<p>
<asp:RadioButtonList ID="RBtonList1" runat="server">
<asp:ListItem>Now</asp:ListItem>
<asp:ListItem>Later</asp:ListItem>
</asp:RadioButtonList> </p>
<p>
</p>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Thank you !" /><br />
<br />
<br />
<asp:Label ID="Lab1" runat="server" Text = "" Width="262px"></asp:Label><br />
<asp:Label ID="Lab2" runat="server" Width="259px"></asp:Label></div>
</form>
</body>
</html>
C#:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Lab1.Text = "";
Lab2.Text = "";
for (int i = 0; i <= 2; i++)
{
if (breakfastitem.Items[i].Selected == true)
{
Lab2.Text += "You have chosen " + breakfastitem.Items[i].Text +"Y for breakfast." + "<br />";
}
}
Lab2.Text += RBtonList1.Text ;
}
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Lab1.Text = "Thank you very much " + DropDownList1.SelectedItem.Text;
Lab1.Text += txtname1.Text + " " + txtname2.Text;
}
protected void breakfastitem_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
下面是我的结果显示:
Thank you very much MR.Joe W
[color=000080]You have chosen CerealY for breakfast.
You have chosen EggsY for breakfast[/color].
Now
可是我想要那个Cereal 跟Eggs 连在一起,不是一句一句重复的
还有我想,当客户选择了用餐之后,在显示结果出来之后,下面就除了一个button是submit 点击之后就进去第二页,又显示一次结果,就是模拟送去厨房那里,有谁给点idea呢~~~
以下是我的代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Please enter your name :<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>MR.</asp:ListItem>
<asp:ListItem>Miss.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
</asp:DropDownList><br />
<asp:TextBox ID="txtname1" runat="server" OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
<br />
<asp:TextBox ID="txtname2" runat="server"></asp:TextBox><br />
<br />
<br />
<br />
<br />
What would you like for breakfast :<br />
<br />
<asp:CheckBoxList ID="breakfastitem" runat="server" OnSelectedIndexChanged="breakfastitem_SelectedIndexChanged">
<asp:ListItem>Cereal</asp:ListItem>
<asp:ListItem>Eggs</asp:ListItem>
<asp:ListItem>Toast</asp:ListItem>
</asp:CheckBoxList><br />
<h4>
Feed me:
</h4>
<p>
<asp:RadioButtonList ID="RBtonList1" runat="server">
<asp:ListItem>Now</asp:ListItem>
<asp:ListItem>Later</asp:ListItem>
</asp:RadioButtonList> </p>
<p>
</p>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Thank you !" /><br />
<br />
<br />
<asp:Label ID="Lab1" runat="server" Text = "" Width="262px"></asp:Label><br />
<asp:Label ID="Lab2" runat="server" Width="259px"></asp:Label></div>
</form>
</body>
</html>
C#:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Lab1.Text = "";
Lab2.Text = "";
for (int i = 0; i <= 2; i++)
{
if (breakfastitem.Items[i].Selected == true)
{
Lab2.Text += "You have chosen " + breakfastitem.Items[i].Text +"Y for breakfast." + "<br />";
}
}
Lab2.Text += RBtonList1.Text ;
}
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Lab1.Text = "Thank you very much " + DropDownList1.SelectedItem.Text;
Lab1.Text += txtname1.Text + " " + txtname2.Text;
}
protected void breakfastitem_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
下面是我的结果显示:
Thank you very much MR.Joe W
[color=000080]You have chosen CerealY for breakfast.
You have chosen EggsY for breakfast[/color].
Now
可是我想要那个Cereal 跟Eggs 连在一起,不是一句一句重复的
还有我想,当客户选择了用餐之后,在显示结果出来之后,下面就除了一个button是submit 点击之后就进去第二页,又显示一次结果,就是模拟送去厨房那里,有谁给点idea呢~~~