学生が学習できるように、C# で乗算表プログラムを作成しました。今夜完成させようとしているクラスのプロジェクトです。
問題は、[回答の確認] ボタンを押すと、「入力文字列の形式が正しくありませんでした」というエラーが表示されることです。投げられます。
これが私のコードです。それは冗長です。テキスト ボックスからの回答が正しいかどうかがチェックされると、エラーがスローされます。私はまだ修正を見つけていません。提案や修正があれば教えてください。
ありがとう、クレイトン
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ContentPages_MySecondCalculator : System.Web.UI.Page
{
int SelectedNum = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTimesTable_Click(object sender, EventArgs e)
{
/*protects against incorrect input **/
int SelectedNum = 0;
switch (drpNumberList.SelectedValue)
{
case "1":
SelectedNum = 1;
break;
case "2":
SelectedNum = 2;
break;
case "3":
SelectedNum = 3;
break;
case "4":
SelectedNum = 4;
break;
case "5":
SelectedNum = 5;
break;
case "6":
SelectedNum = 6;
break;
case "7":
SelectedNum = 7;
break;
case "8":
SelectedNum = 8;
break;
case "9":
SelectedNum = 9;
break;
case "10":
SelectedNum = 10;
break;
case "11":
SelectedNum = 11;
break;
case "12":
SelectedNum = 12;
break;
}
/* the first list of numbers are set to their values here **/
lbl1.Text = SelectedNum.ToString();
lbl1b.Text = SelectedNum.ToString();
lbl1c.Text = SelectedNum.ToString();
lbl1d.Text = SelectedNum.ToString();
lbl1e.Text = SelectedNum.ToString();
lbl1f.Text = SelectedNum.ToString();
lbl1g.Text = SelectedNum.ToString();
lbl1h.Text = SelectedNum.ToString();
lbl1i.Text = SelectedNum.ToString();
lbl1j.Text = SelectedNum.ToString();
lbl1k.Text = SelectedNum.ToString();
lbl1l.Text = SelectedNum.ToString();
/* the second list of numbers that appears are set to their values here **/
lbl2a.Text = "1";
lbl2b.Text = "2";
lbl2c.Text = "3";
lbl2d.Text = "4";
lbl2e.Text = "5";
lbl2f.Text = "6";
lbl2g.Text = "7";
lbl2h.Text = "8";
lbl2i.Text = "9";
lbl2j.Text = "10";
lbl2k.Text = "11";
lbl2l.Text = "12";
}
// in case no input was taken
protected void lblNumberList_SelectedIndexChanged(object sender, EventArgs e)
{
}
/*
protected void txtBox1_TextChanged(object sender, EventArgs e)
{
}
* */
protected void btnCheckAnswers_Click(object sender, EventArgs e)
{
if (true)
{
lblFeedback1.Text = "correct";
}
else
{
lblFeedback1.Text = "incorrect";
}
if (true)
{
lblFeedback2.Text = "correct";
}
else
{
lblFeedback2.Text = "incorrect";
}
if (true)
{
lblFeedback3.Text = "correct";
}
else
{
lblFeedback3.Text = "incorrect";
}
if (true)
{
lblFeedback4.Text = "correct";
}
else
{
lblFeedback4.Text = "incorrect";
}
if (true)
{
lblFeedback5.Text = "correct";
}
else
{
lblFeedback5.Text = "incorrect";
}
if (true)
{
lblFeedback6.Text = "correct";
}
else
{
lblFeedback6.Text = "incorrect";
}
if (true)
{
lblFeedback7.Text = "correct";
}
else
{
lblFeedback7.Text = "incorrect";
}
if (true)
{
lblFeedback8.Text = "correct";
}
else
{
lblFeedback8.Text = "incorrect";
}
if (true)
{
lblFeedback9.Text = "correct";
}
else
{
lblFeedback9.Text = "incorrect";
}
if (true)
{
lblFeedback10.Text = "correct";
}
else
{
lblFeedback10.Text = "incorrect";
}
if (true)
{
lblFeedback11.Text = "correct";
}
else
{
lblFeedback11.Text = "incorrect";
}
if (true)
{
lblFeedback12.Text = "correct";
}
else
{
lblFeedback12.Text = "incorrect";
}
/*
if ((Convert.ToInt32(txtBox1.ToString())) == SelectedNum)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 2)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 3)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 4)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 5)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 6)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 7)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 8)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 9)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 10)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 11)
{
}
if ((Convert.ToInt32(txtBox2.ToString())) == SelectedNum * 12)
{
}
* */
}
}