在控件之间动态添加

时间:2022-07-02 16:50:16

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

我在我的网页上动态列出了一些控件,或者我添加了换行标签。

Label newLine = new Label();newLine.Text = "<br/>"; myPanel.Controls.Add(newLine);

How can I do it in a different way?

我怎样才能用不同的方式去做呢?

3 个解决方案

#1


70  

myPanel.Controls.Add(new LiteralControl("<br />"));

#2


1  

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!

我建议你不要用。使用CSS显示控件。显示:您的元素上的块将会正常工作。更少的混乱!

#3


0  

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

我的问题是:向指示日期范围的面板添加文本。文本应该放在超链接下面。

The CSS solution:

CSS解决方案:

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

a .创建CSS类(将它放在页面或CSS文件中)

.dateRange
{
    display:block;
}

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

创建控件并设置适当的CSS类(。CssClass属性)

//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:

最终输出如下所示:

在控件之间动态添加

Sources:

来源:

#1


70  

myPanel.Controls.Add(new LiteralControl("<br />"));

#2


1  

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!

我建议你不要用。使用CSS显示控件。显示:您的元素上的块将会正常工作。更少的混乱!

#3


0  

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

我的问题是:向指示日期范围的面板添加文本。文本应该放在超链接下面。

The CSS solution:

CSS解决方案:

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

a .创建CSS类(将它放在页面或CSS文件中)

.dateRange
{
    display:block;
}

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

创建控件并设置适当的CSS类(。CssClass属性)

//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:

最终输出如下所示:

在控件之间动态添加

Sources:

来源: