我写了一个是学生给老师评分的页面,动态生成的table,有几个老师就有几行,评分涉及各个方面,每个表格里是3个radio单选按钮,代表不同的分值,只能选一个,但是我现在的问题是怎么才能知道学生选的是哪个radio按钮,也就是怎么获取
table中控件的属性或状态,这样我才能写入数据库,到底该怎么做??
另:用table.rows[].Cells[].innerText也不行啊
附上我的动态表格代码:
mycon = databaseConnection.DBCon();
int numrows;
int numcells;
int i = 0;
int j = 0;
int row = 0;
TableRow r;
TableCell c;
String b =
"<form id=\"form1\" name=\"form1\" method=\"post\"" +
"action=\"\"><label><input type=\"radio\" name=\"radiobutton\" " +
"value=\"radiobutton\" />1</label><p><label><input type=\"radio\" " +
"name=\"radiobutton\" value=\"radiobutton\" />2</label></p></form>";
String[] ITEM = new string[] { "1", "2", "3", "4" }; DataSet ds = new DataSet();
mycon.Open();
String sql = "SELECT teachers.teacherName from teachers";
SqlDataAdapter sda = new SqlDataAdapter(sql, mycon);
sda.Fill(ds, "temp");
mycon.Close();
numrows = ds.Tables["temp"].Rows.Count + 1;
//产生表格
numcells = 4;
for (i = 0; i < numrows; i++)
{
r = new TableRow();
if (row / 2 != 0)
{
r.BorderColor = System.Drawing.Color.Red;
}
row += 1;
for (j = 0; j < numcells; j++)
{
if (i == 0)
{
if (j == 0)
{
c = new TableCell();
c.Controls.Add(new LiteralControl(" "));
r.Cells.Add(c);
}
else
{
c = new TableCell();
c.Controls.Add(new LiteralControl(ITEM[j]));
r.Cells.Add(c);
}
}
if ((j == 0) && (i != 0))
{
c = new TableCell();
c.Controls.Add(new LiteralControl(ds.Tables["temp"].Rows[i - 1][0].ToString()));
r.Cells.Add(c);
}
if ((i != 0) && (j != 0))
{
c = new TableCell();
c.Controls.Add(new LiteralControl(b));
r.Cells.Add(c);
}
}
Table1.Rows.Add(r);
}
table中控件的属性或状态,这样我才能写入数据库,到底该怎么做??
另:用table.rows[].Cells[].innerText也不行啊
附上我的动态表格代码:
mycon = databaseConnection.DBCon();
int numrows;
int numcells;
int i = 0;
int j = 0;
int row = 0;
TableRow r;
TableCell c;
String b =
"<form id=\"form1\" name=\"form1\" method=\"post\"" +
"action=\"\"><label><input type=\"radio\" name=\"radiobutton\" " +
"value=\"radiobutton\" />1</label><p><label><input type=\"radio\" " +
"name=\"radiobutton\" value=\"radiobutton\" />2</label></p></form>";
String[] ITEM = new string[] { "1", "2", "3", "4" }; DataSet ds = new DataSet();
mycon.Open();
String sql = "SELECT teachers.teacherName from teachers";
SqlDataAdapter sda = new SqlDataAdapter(sql, mycon);
sda.Fill(ds, "temp");
mycon.Close();
numrows = ds.Tables["temp"].Rows.Count + 1;
//产生表格
numcells = 4;
for (i = 0; i < numrows; i++)
{
r = new TableRow();
if (row / 2 != 0)
{
r.BorderColor = System.Drawing.Color.Red;
}
row += 1;
for (j = 0; j < numcells; j++)
{
if (i == 0)
{
if (j == 0)
{
c = new TableCell();
c.Controls.Add(new LiteralControl(" "));
r.Cells.Add(c);
}
else
{
c = new TableCell();
c.Controls.Add(new LiteralControl(ITEM[j]));
r.Cells.Add(c);
}
}
if ((j == 0) && (i != 0))
{
c = new TableCell();
c.Controls.Add(new LiteralControl(ds.Tables["temp"].Rows[i - 1][0].ToString()));
r.Cells.Add(c);
}
if ((i != 0) && (j != 0))
{
c = new TableCell();
c.Controls.Add(new LiteralControl(b));
r.Cells.Add(c);
}
}
Table1.Rows.Add(r);
}
r.Cells.Add(c);
RadionButton rb=new RadioButton();
......
c.Controls.Add(rb);而不是什么 new LiteralControl(b))。
但是如果照我前面的方法用c.Controls.Add(new LiteralControl(b));整个表格就都有了,我不知道问题出在哪儿