How to create line breaks between dynamically generated labels in a placeholder?

前端 未结 3 850
谎友^
谎友^ 2021-02-19 01:45

This is the code below in code behind file\'s Page_Load event:

        LinkButton linkButton = new LinkButton();
        linkButton.ID = \"LinkButto         


        
3条回答
  •  自闭症患者
    2021-02-19 02:09

    Another solution is that you could add each control to a Panel, which will render them each in a

    resulting in the effect you're looking for.

    To me this would be more dynamic because if you hide any of the controls the div will collapse and not leave empty lines.

        LinkButton linkButton = new LinkButton();
        linkButton.ID = "LinkButtonDynamicInPlaceHolder1Id" + i;
        linkButton.ForeColor = Color.Blue;
        linkButton.Font.Bold = true;
        linkButton.Font.Size = 14;
        linkButton.Font.Underline = false;
        linkButton.Text = itemList[i].ItemTitle.InnerText;
        linkButton.Click += new EventHandler(LinkButton_Click);
        linkButton.Attributes.Add("LinkUrl",itemList[i].ItemLink.InnerText);
    
        //Add control to a panel, add panel to placeholder
        Panel lbPan = new Panel();
        lbPan.Controls.Add(linkButton); 
        PlaceHolder1.Controls.Add(lbPan);
    
    
        Label label = new Label();
        label.ID = "LabelDynamicInPlaceHolder1Id" + i;
        label.ForeColor = Color.DarkGray;
        label.Text = itemList[i].ItemDescription.InnerText;
    
        //Add control to a panel, add panel to placeholder
        Panel lblPan = new Panel();
        lblPan.Controls.Add(label); 
        PlaceHolder1.Controls.Add(lblPan);
    

提交回复
热议问题