Adding
dynamically between controls asp.net

后端 未结 3 1201
长发绾君心
长发绾君心 2020-12-17 08:05

I\'m listing some controls at my web page dynamically, either I\'m adding newline with Label\'s.

Label newLine = new Label();newLine.Text = \"
\";
相关标签:
3条回答
  • 2020-12-17 08:16

    I would suggest that you don't use
    at all. Use CSS to display your controls. display:block on your elements will work just fine. Less messy!

    0 讨论(0)
  • 2020-12-17 08:32
    myPanel.Controls.Add(new LiteralControl("<br />"));
    
    0 讨论(0)
  • 2020-12-17 08:33

    My problem: Add a text to a panel indicating a date range. The text should be placed below an hyperlink.

    The CSS solution:

    A. Create the CSS class (place it on your page or into a CSS file)

    .dateRange
    {
        display:block;
    }
    

    B. Create controls and set the proper CSS class (.CssClass property)

    //1. Create the link
    LinkButton _btnTitle = new LinkButton();
    _btnTitle.Text = Request.QueryString["name"];
    _btnTitle.OnClientClick = "history.go(-1); return false;";
    _btnTitle.ToolTip = Request.QueryString["name"];
    _btnTitle.CssClass = "title";
    
    //2. Add the link to the container
    pnlFindTech.Controls.Add(_btnTitle);  
    
    //3. Create the label (text)    
    Label lblDate = new Label();
    lblDate.Text = " [ From " + txtDateFrom.Text + " To " + txtDateTo.Text + " ] ";
    lblDate.CssClass = "dateRange"; //Here is the trick
    
    //4. Add the label to the container
    pnlFindTech.Controls.Add(lblDate);
    

    The final output looks like the this:

    enter image description here

    Sources:

    • CSS display Property (w3schools)

    • Example (w3schools)

    0 讨论(0)
提交回复
热议问题