ASP.NET动态创建控件之绝境求生
日期:2007年9月8日 作者: 查看:[大字体 中字体 小字体]
-
border="0" marginwidth="0" marginheight="0" src="http://www.hackhome.com/gg/web/ff_468.html" frameborder="no" width="468" scrolling="no" height="0"> - <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-0692289505803928&dt=1206920378562&lmt=1199929998&format=300x250_as&output=html&correlator=1206920378562&channel=6926205886&url=http%3A%2F%2Fwww.hackhome.com%2FInfoView%2FArticle_152410_2.html&color_bg=FFFFFF&color_text=000000&color_link=000060&color_url=008000&color_border=FFFFFF&ad_type=text_image&ref=http%3A%2F%2Fwww.hackhome.com%2FInfoView%2FArticle_152410.html&frm=0&cc=100&ga_vid=1409738354.1206920379&ga_sid=1206920379&ga_hid=579533993&flash=9.0.47.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_his=1&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency="allowtransparency"> </form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
private int _count = 0;protected override void OnInit(EventArgs e)
{
base.OnInit(e);// 取得以前已创建控件的个数
if (!String.IsNullOrEmpty(this.Request["hfCount"]))
{
_count = Convert.ToInt32(this.Request["hfCount"]);
}// 假如按下“Add”按钮,那么count加一
string target = this.Request["btnAdd"];
if (target == "Add")
{
_count++;
}// 动态创建控件
for (int i = 0; i < _count; i++)
{ // 这里以TextBox为例,实际上需要创建的是WebPartZone
TextBox newTextbox = new TextBox();
newTextbox.ID = "TXT" + i.ToString();