前端代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
后端代码:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { int s = 0; for (int i = 1; i <= 10; i++) { s += i; } Response.Write("1到10的和为" + s.ToString()); } protected void Button2_Click(object sender, EventArgs e) { if (Rn1.Checked) {TextBox1.Text = "你选中了:"+Rn1.Text;} if (Rn2.Checked) {TextBox1.Text = "你选中了:"+Rn2.Text;} if (Rn3.Checked) {TextBox1.Text = "你选中了:"+Rn3.Text;} if (Rn4.Checked) { TextBox1.Text = "你选中了:" + Rn4.Text; } } protected void Button3_Click(object sender, EventArgs e) { //将文本框的值转化成 浮点型 double num = -1; //每次运行之前要清空所选中的文本框 Label1.Text = ""; Ran1.Checked = false; Ran2.Checked = false; Ran3.Checked = false; Ran4.Checked = false; //先将文本框的值 转换成浮点型,再将其赋值给num, //因为num事先已经是-1了, try{num = double.Parse(TextBox2.Text);} catch {} if (num < 0 || num > 120) { Label1.Text = "请输入正确的数字"; } else{ if(num<60){Ran1.Checked = true;} if(num>60&&num<80){Ran2.Checked = true;} if(num>80&&num<100){Ran3.Checked = true;} if(num>100&&num<120){Ran4.Checked = true;} } } protected void rr1(object sender, EventArgs e) { if (R1.Checked == true) { Label2.Text = "你选择了" + R1.Text; } } protected void rr2(object sender, EventArgs e) { if (R2.Checked == true) { Label2.Text = "你选择了" + R2.Text; } } protected void rr3(object sender, EventArgs e) { if (R3.Checked == true) { Label2.Text = "你选择了" + R3.Text; } } protected void rr4(object sender, EventArgs e) { if (R4.Checked == true) { Label2.Text = "你选择了" + R4.Text; } } protected void Button_Click(object sender, EventArgs e) { if (R1.Checked == false && R2.Checked == false && R3.Checked == false && R4.Checked == false) { Response.Write(""); } else if (R2.Checked) { Response.Write(""); } else { Response.Write(""); } }}