动态生成的checkbox
HtmlTableRow tempRow = new HtmlTableRow();
HtmlTableCell cellCheck = new HtmlTableCell();
CheckBox chk = new CheckBox();
chk.ID = "chk"+row.ToString();
cellCheck.Controls.Add(chk);
tempRow.Cells.Add(cellCheck);
Table.rows.add(tempRow);怎样能找到动态生成的这些checkbox,注意以上代码不是在page_load里面执行的CheckBox chkCon = new CheckBox();
for(int i=1;i<rowCount;i++)
{
int row = i+1;
string id = "chk"+row.ToString();
chkCon = (CheckBox)this.Table.Rows[i].Cells[0].Controls[0];
chkCon.Checked = true;
}
试个上面的那个方法,不行,请高手指教!!!
HtmlTableRow tempRow = new HtmlTableRow();
HtmlTableCell cellCheck = new HtmlTableCell();
CheckBox chk = new CheckBox();
chk.ID = "chk"+row.ToString();
cellCheck.Controls.Add(chk);
tempRow.Cells.Add(cellCheck);
Table.rows.add(tempRow);怎样能找到动态生成的这些checkbox,注意以上代码不是在page_load里面执行的CheckBox chkCon = new CheckBox();
for(int i=1;i<rowCount;i++)
{
int row = i+1;
string id = "chk"+row.ToString();
chkCon = (CheckBox)this.Table.Rows[i].Cells[0].Controls[0];
chkCon.Checked = true;
}
试个上面的那个方法,不行,请高手指教!!!
this.Table.Rows[i].Cells[0].Controls[0];
this.Table.Rows[i].Cells[0].Controls[1]; 分别是什么控件。
for(int i=1;i <rowCount;i++)
{
int row = i+1;
string id = "chk"+row.ToString();
if ((CheckBox)this.Table.Rows[i].Cells[0].Controls[0]).Checked)
chkCon.Checked = true;
else
chkCon.Checked = false;
}
2.看一下这些控件的父级都是些什么.然后再确定find
public void cc()
{
CheckBox ck = new CheckBox();
ck.Text = "123";
ck.ID = "chk123";
Panel1.Controls.Add(ck);
}
要是找不着 看再调试下页面的加载过程 。
一般这种动态改变页面控件的效果是由客户端实现的。
如果非要用服务端,我倒是有个不成熟的想法。
.cs
protected void Page_Load(object sender,EventArgs e)
{
if(IsPostBack)
{
Label lb=new Label();
lb.Text=ViewState["xx"].ToString();
}
}
protected void Button1_Click(object sender,EventArgs e)
{
ViewState["xx"]=yourvalue;
}
没有试过,很有可能是错的莫怪。
Table1.Rows.Add(row);
TableCell column1 = new TableCell();
row.Cells.Add(column1);
CheckBox chk = new CheckBox();
column1.Controls.Add(chk);
这样就可以了啊