当前位置: 代码迷 >> ASP.NET >> webform在指定的div中添加动态添加label,该怎么解决
  详细解决方案

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

热度:5427   发布时间:2013-02-25 00:00:00.0
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 />");            });        });
  相关解决方案