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

webform在指定的div中添加动态添加label,该怎么解决

2012-04-15 
webform在指定的div中添加动态添加labelRT[解决办法]二、动态生成Asp.Net服务器控件,并取其值C# codeprivat

webform在指定的div中添加动态添加label
RT

[解决办法]
二、动态生成Asp.Net服务器控件,并取其值

C# code
private void LoadProperty(int cateId){    HtmlGenericControl span = new HtmlGenericControl();    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)    {              StringBuilder strHtml = new StringBuilder();         if (i % 2 == 0)         {              strHtml.Append("<div >");              strHtml.Append("<div class=\"layout1\">");         }         else         {                                              strHtml.Append("<div >");          }                             TextBox txt = new TextBox();          Label lbl = new Label();          HiddenField hdf = new HiddenField();//          lbl.ID = "lblProp" + i.ToString();          lbl.Text = ds.Tables[0].Rows[i]["PropName"].ToString() + ":";          txt.ID = "txtProp" + i.ToString();          hdf.ID = "hdfProp" + i.ToString();//          lbl.EnableViewState = true;          txt.EnableViewState = true;          hdf.EnableViewState = true;//          LiteralControl lc = new LiteralControl(strHtml.ToString());          lc.EnableViewState = true;          span.Controls.Add(lc);          span.Controls.Add(lbl);          span.Controls.Add(txt);          span.Controls.Add(hdf);//                             if (i % 2 == 0)          {                span.Controls.Add(new LiteralControl("</div></div>"));          }          else           {                 span.Controls.Add(new LiteralControl("</div>"));           }              } }动态生成的控件,当点击页面按钮时会刷新页面,所以,生成控件的方法不需要if(!IsPostBack){}
[解决办法]
JScript code
$(function(){                           $("#addLabel").click(function(){                $("#divAddLabel").append("<label>添加的label<label/><br />");            });        }); 

热点排行