读书人

求救!怎样获取table中控件的状态或值

发布时间: 2012-02-24 16:30:39 作者: rapoo

求救!怎样获取table中控件的状态或值
做了一个教师评价表,有教师人数动态生成table,并在每个表格单元中加入了RadioButtoList控件,每个控件包含3个radioButton,表示3种不同的分数。现在的问题是我怎样才能知道学生选的是哪个分值,因为要进行每位老师的分数统计(哪位大虾具体讲一下)
代码如下:
public partial class assessTable : System.Web.UI.Page
{
SqlConnection mycon;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
mycon = databaseConnection.DBCon();
int numrows;
int numcells;
int i = 0;
int j = 0;
int row = 0;
TableRow r;
TableCell c;

String[] ITEM = new string[] { "上课积极,不迟到 ",
"对学生很负责, "+
"很友好,有问必答 ",
"教学严谨,学术过硬 ",
"和蔼可亲 " };

RadioButton rb = new RadioButton();

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 = ITEM.Length;
for (i = 0; i < numrows; i++)
{
r = new TableRow();
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);
}
if(j != 0)


{
c = new TableCell();
c.Controls.Add(new LiteralControl(ITEM[j-1]));
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();
RadioButtonList rbList = CreateRadioButtonList();
rbList.ID = i.ToString() + j.ToString();
c.Controls.Add(rbList);


r.Cells.Add(c);
}
}
Table1.Rows.Add(r);
}
}

}
protected void Button1_Click1(object sender, EventArgs e)
{

}
protected static RadioButtonList CreateRadioButtonList()
{
ArrayList myList = new ArrayList();
RadioButtonList myRadioList = new RadioButtonList();
myList.Add( "很差(0分) ");
myList.Add( "一般般(1分) ");
myList.Add( "不错(2分) ");
myList.Add( "非常好(3分) ");
myRadioList.DataSource = myList;
myRadioList.DataBind();
myRadioList.EnableViewState = true;
myRadioList.CssClass = "RadioButtonList ";
return myRadioList;
}

}

[解决办法]
你最好先不要去处理什么“怎样获取控件中状态”的问题,先做到这样的测试用例:

给页面aspx上随便拖入一个Button,为它设置一个点击事件,使得它点击的时候可以让页面postback。然后,实际测试,当操作页面上其它控件时交叉点击按钮,反复提交页面,此时页面上所有控件的状态(值、样式等等)必须永远自动保持最后一次操作之后。如果点击按钮会令其它控件丢失状态信息,那么这些控件连最起码的asp.net程序回发运行逻辑都没有实现。

读书人网 >asp.net

热点推荐