如何对动态生成的控件进行操作。
动态生成控件功能已经实现。只是在执行其它操作的同时页面刷新(点击其它Button按钮时)会隐藏掉先前生成的控件。
使用this.Controls.Count也无法找到,请问如何解决此问题。贴出动态生成控件的方法
protected void BindParametersInfo(string strDeviceTypeID,Panel tempPanel) { int Cyci=0;
DataTable tempDT=new DataTable();
HtmlTable tempHtmlTable=new HtmlTable();
tempHtmlTable.Width="100%"; try { strSql=string.Empty;
strSql="";
tempDT=DataProcessing.Select(strSql).Tables[0]; while (Cyci<tempDT.Rows.Count) { HtmlTableRow tempHtmlTableRow=new HtmlTableRow(); if (Cyci>=tempDT.Rows.Count) break; HtmlTableCell tempHtmlTableCell1=new HtmlTableCell();
tempHtmlTableCell1.Width="100";
Label tempLB1=new Label();
tempLB1.ID="LB_"+Cyci.ToString();
tempLB1.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempLB1.Width=98;
tempLB1.Visible = true;
tempHtmlTableCell1.Controls.Add(tempLB1);
tempHtmlTableCell1.Align="right";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell1); HtmlTableCell tempHtmlTableCell2=new HtmlTableCell();
tempHtmlTableCell2.Width="187";
TextBox tempBox1=new TextBox();
tempBox1.ID="TBox_"+Cyci.ToString();
tempBox1.Visible=true;
tempBox1.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempBox1.Width=183;
tempHtmlTableCell2.Controls.Add(tempBox1);
tempHtmlTableCell2.Align="left";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell2); Cyci++;
if (Cyci>=tempDT.Rows.Count) break; HtmlTableCell tempHtmlTableCell3=new HtmlTableCell();
tempHtmlTableCell3.Width="100";
Label tempLB2=new Label();
tempLB2.Visible = true;
tempLB2.ID="LB_"+Cyci.ToString();
tempLB2.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempLB2.Width=98;
tempHtmlTableCell3.Controls.Add(tempLB2);
tempHtmlTableCell3.Align="right";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell3); HtmlTableCell tempHtmlTableCell4=new HtmlTableCell();
tempHtmlTableCell4.Width="187";
TextBox tempBox2=new TextBox();
tempBox2.ID="TBOX_"+Cyci.ToString();
tempBox2.Visible = true;
tempBox2.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempBox2.Width=183;
tempHtmlTableCell4.Controls.Add(tempBox2);
tempHtmlTableCell4.Align="left";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell4); tempHtmlTable.Rows.Add(tempHtmlTableRow);
Cyci++;
}
tempPanel.Controls.Add(tempHtmlTable);
} catch {
}
}
动态生成控件功能已经实现。只是在执行其它操作的同时页面刷新(点击其它Button按钮时)会隐藏掉先前生成的控件。
使用this.Controls.Count也无法找到,请问如何解决此问题。贴出动态生成控件的方法
protected void BindParametersInfo(string strDeviceTypeID,Panel tempPanel) { int Cyci=0;
DataTable tempDT=new DataTable();
HtmlTable tempHtmlTable=new HtmlTable();
tempHtmlTable.Width="100%"; try { strSql=string.Empty;
strSql="";
tempDT=DataProcessing.Select(strSql).Tables[0]; while (Cyci<tempDT.Rows.Count) { HtmlTableRow tempHtmlTableRow=new HtmlTableRow(); if (Cyci>=tempDT.Rows.Count) break; HtmlTableCell tempHtmlTableCell1=new HtmlTableCell();
tempHtmlTableCell1.Width="100";
Label tempLB1=new Label();
tempLB1.ID="LB_"+Cyci.ToString();
tempLB1.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempLB1.Width=98;
tempLB1.Visible = true;
tempHtmlTableCell1.Controls.Add(tempLB1);
tempHtmlTableCell1.Align="right";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell1); HtmlTableCell tempHtmlTableCell2=new HtmlTableCell();
tempHtmlTableCell2.Width="187";
TextBox tempBox1=new TextBox();
tempBox1.ID="TBox_"+Cyci.ToString();
tempBox1.Visible=true;
tempBox1.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempBox1.Width=183;
tempHtmlTableCell2.Controls.Add(tempBox1);
tempHtmlTableCell2.Align="left";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell2); Cyci++;
if (Cyci>=tempDT.Rows.Count) break; HtmlTableCell tempHtmlTableCell3=new HtmlTableCell();
tempHtmlTableCell3.Width="100";
Label tempLB2=new Label();
tempLB2.Visible = true;
tempLB2.ID="LB_"+Cyci.ToString();
tempLB2.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempLB2.Width=98;
tempHtmlTableCell3.Controls.Add(tempLB2);
tempHtmlTableCell3.Align="right";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell3); HtmlTableCell tempHtmlTableCell4=new HtmlTableCell();
tempHtmlTableCell4.Width="187";
TextBox tempBox2=new TextBox();
tempBox2.ID="TBOX_"+Cyci.ToString();
tempBox2.Visible = true;
tempBox2.Text=tempDT.Rows[Cyci]["ParametersName"].ToString();
tempBox2.Width=183;
tempHtmlTableCell4.Controls.Add(tempBox2);
tempHtmlTableCell4.Align="left";
tempHtmlTableRow.Cells.Add(tempHtmlTableCell4); tempHtmlTable.Rows.Add(tempHtmlTableRow);
Cyci++;
}
tempPanel.Controls.Add(tempHtmlTable);
} catch {
}
}
{}
要确保你在每次page_load时都执行生成控件的代码