首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎样获取table中控件的属性或状态解决思路

2012-01-03 
怎样获取table中控件的属性或状态我写了一个是学生给老师评分的页面,动态生成的table,有几个老师就有几行,

怎样获取table中控件的属性或状态
我写了一个是学生给老师评分的页面,动态生成的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);
                }

[解决办法]
你的代码丝毫没有符合控件开发的影子。看那个“String b”,我觉得你还是去考虑javascript吧,你没有构造起asp.net控件树,不要奢谈asp.net的Radio控件。你在可以在javascript程序中处理按钮。

asp.net的复合控件,至少会有类似这样的代码:

c = new TableCell();
r.Cells.Add(c);
RadionButton rb=new RadioButton();
......
c.Controls.Add(rb);

而不是什么 new LiteralControl(b))。

热点排行
Bad Request.