日期:2014-05-18 浏览次数:20545 次
[Serializable]
public partial class _Default : System.Web.UI.Page
{
RadioButton[] radYes ;
RadioButton[] radNo ;
public static int num = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
radYes =new RadioButton[47];
radNo = new RadioButton[47];
displaySource();
}
else
{
radYes = (RadioButton[])ViewState["radYes"];
}
}
public void displaySource()
{
StreamReader sr = new StreamReader(Server.MapPath("~/source.txt"), Encoding.Default);
TableRow tr;
TableCell tc;
int count = 0;
while (!sr.EndOfStream)
{
count++;
string txt = sr.ReadLine();
string[] content = txt.Split('@');
tr= new TableRow();
tc = new TableCell();
tc.Text = content[0];
tr.Cells.Add(tc);
radYes[count - 1] = new RadioButton();
radYes[count-1].Text = "是";
radYes[count - 1].ID = "yes" + count;
radYes[count - 1].Attributes.Add("value", content[1]);
radYes[count - 1].GroupName = "e" + count;
tc = new TableCell();
tc.Controls.Add(radYes[count - 1]);
tr.Cells.Add(tc);
radNo[count - 1] = new RadioButton();
radNo[count - 1].Text = "不是 ";
radNo[count - 1].ID = "no" + count;
radNo[count - 1].Attributes.Add("value", content[1]);
radNo[count - 1].GroupName = "e" + count;
tc = new TableCell();
tc.Controls.Add(radNo[count - 1]);
tr.Cells.Add(tc);
tblDisplay.Rows.Add(tr);
}
num = count;
ViewState["radYes"] = radYes;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//ViewState["radYes"] = counter;
int[] type = new int[9];
for (int i = 0; i < radYes.Length; i++)
{
if (radYes[i].Checked)
{
int res = int.Parse(radYes[i].ID.Substring(3, 1));
type[res - 1]++;
}
}
for (int i = 0; i < type.Length; i++)
{
Response.Write((i+1)+"号性格: "+type[i].ToString()+"<br/>");
}
}
}