2013-10-09 97 views

回答

0

這裏是一個非常有用的鏈路,並解釋爲什麼
link from here

  • 動態

加載對於實施例

時始終加入Page_PreInit()的動態控制
  • 始終分配ID
    protected void Page_PreInit(object sender, EventArgs e) 
    { 
         Control c= LoadControl("./WebUserControl2.ascx"); 
         i=i+1; 
         c.ID= i.ToString(); 
         PlaceHolder1.Controls.Add(c); 
    } 
    

    protected void Page_PreInit(object sender, EventArgs e) 
    { 
         LinkButton button1 = new LinkButton(); 
         button1.ID = "button1" 
         button1.Text = "button1" 
         PlaceHolder1.Controls.Add(button1); 
    } 
    
  • 0

    嘗試這種方式

    for (int j = 0; j < 10; j++) 
          {     
    
           //Create Dynamic textboxes with required field validator . 
    
           TextBox tbChildFirstName = new TextBox(); 
           Label lblChildFirstName = new Label(); 
           lblChildFirstName.ID = "lblChildFirstName" + j; 
           lblChildFirstName.Text = "Children FirstName"; 
           lblChildFirstName.Width = 200; 
           lblChildFirstName.SkinID = "Outlabel"; 
           tbChildFirstName.ID = "txtChildFirstName" + j; 
           tbChildFirstName.Text = "Hi hello"; 
           pnlChildDetail.Controls.Add(lblChildFirstName); 
           pnlChildDetail.Controls.Add(tbChildFirstName); 
           RequiredFieldValidator rqf = new RequiredFieldValidator(); 
           rqf.ID = "rqf" + i; 
           pnlChildDetail.Controls.Add(rqf); 
           rqf.ControlToValidate = "txtChildFirstName" + j; 
           rqf.ErrorMessage = "Children FirstName is required"; 
           rqf.Display = ValidatorDisplay.Dynamic; 
           rqf.ValidationGroup = "EligibilityCheck"; 
           rqf.SetFocusOnError = true; 
           rqf.Text = "*"; 
           tbChildFirstName.Attributes.Add("runat", "server"); 
           pnlChildDetail.Controls.Add(GetLiteral("<br/>")); 
           pnlChildDetail.Controls.Add(GetLiteral("<br/>")); 
    
          } 
    
    public Literal GetLiteral(string text) 
        { 
         Literal rv = default(Literal); 
         rv = new Literal(); 
         rv.Text = text; 
         return rv; 
        } 
    

    .aspx的

    <asp:Panel ID="pnlChildDetail" Style="text-align: left; padding-left: 10px" Width="100%" 
         runat="server"> 
        </asp:Panel> 
    

    更多細節創建動態文本形式的數據庫數據計數以及如何動態文本框的值:?看到我blog

    相關問題