生成.显示正常(CB是全局的 protected System.Web.UI.WebControls .CheckBox cb;)
======================
TableRow tr= new TableRow();
this.TableModel .Rows.Add(tr);
tr.Cells .Add(tc);
cb=new CheckBox();
tc.Controls .Add (cb);
========================检测,运行报错
==========================
if(((CheckBox)TableModel .Rows[0].Cells[0].FindControl ("cb")).Checked ==true)
alert('ok');
==========================
运行提示 未将对象引用设置到对象的实例。
指出的错误就是if(((CheckBox)TableModel .Rows[0].Cells[0].FindControl ("cb")).Checked ==true)这句,求高手指教.(第一行是列头,我改为if(((CheckBox)TableModel .Rows[1].Cells[0].FindControl ("cb")).Checked ==true)也报错)
======================
TableRow tr= new TableRow();
this.TableModel .Rows.Add(tr);
tr.Cells .Add(tc);
cb=new CheckBox();
tc.Controls .Add (cb);
========================检测,运行报错
==========================
if(((CheckBox)TableModel .Rows[0].Cells[0].FindControl ("cb")).Checked ==true)
alert('ok');
==========================
运行提示 未将对象引用设置到对象的实例。
指出的错误就是if(((CheckBox)TableModel .Rows[0].Cells[0].FindControl ("cb")).Checked ==true)这句,求高手指教.(第一行是列头,我改为if(((CheckBox)TableModel .Rows[1].Cells[0].FindControl ("cb")).Checked ==true)也报错)
要给动态控件赋一个id,postback之后用Request.From["控件id"]来取值
TableRow tr= new TableRow();
this.TableModel .Rows.Add(tr);
TableCell tc=new TableCell();
tr.Cells .Add(tc);
cb=new CheckBox();
tc.Controls .Add (cb);
加入我给cb.ID=CB+i(行号)
那POSTBACK后怎么知道那行曾经选中过呢,关键的一句代码怎么写呢
cell.Controls.Add(cb)
row.Controls.Add(cell)
if(((CheckBox)DataGrid1.Items[i].Cells[0].FindControl("check1")).Checked == true),我在datagrid中是可以的,但换成动态表格怎么就不行了呢
override protected void OnInit(EventArgs e)函数中。
这个函数是自动生成的。先于page_load函数运行。TableRow tr= new TableRow();
this.TableModel .Rows.Add(tr);
tr.Cells .Add(tc);
cb=new CheckBox();
tc.Controls .Add (cb);管用的话给分啊。哈哈