1 protected void Button1_Click(object sender, EventArgs e)
2 {
3 ListBox1.Items.Clear();//清空ListBox控件
4 int p = 0, n = 0, a = 1, b = 1;//定义变量
5 try
6 {
7 p = Convert.ToInt32(TextBox1.Text);//将字符型转换成数值型
8 }
9 catch//出现错误
10 {
11 Response.Write("<script>alert('请输入数值型数据');</script>");
12 TextBox1.Text = "15";
13 return;
14 }
15 for (n = 1; n <= p; n++)//对输入的数值进行遍历
16 {
17 ListBox1.Items.Add(a.ToString());//输出数值
18 ListBox1.Items.Add(b.ToString());//输出数值
19 a = a + b;//获取前两个数的和
20 b = a + b;//获取前两个数的和
21 }
22 }
2 {
3 ListBox1.Items.Clear();//清空ListBox控件
4 int p = 0, n = 0, a = 1, b = 1;//定义变量
5 try
6 {
7 p = Convert.ToInt32(TextBox1.Text);//将字符型转换成数值型
8 }
9 catch//出现错误
10 {
11 Response.Write("<script>alert('请输入数值型数据');</script>");
12 TextBox1.Text = "15";
13 return;
14 }
15 for (n = 1; n <= p; n++)//对输入的数值进行遍历
16 {
17 ListBox1.Items.Add(a.ToString());//输出数值
18 ListBox1.Items.Add(b.ToString());//输出数值
19 a = a + b;//获取前两个数的和
20 b = a + b;//获取前两个数的和
21 }
22 }