问题描述
这是我从C#代码创建文本框的代码。
here is the code I create textbox from C# code..
for (int x = 0; x < 30; x++)
{
TextBox txt = new TextBox();
txt.ID = "txt - " + x.ToString();
data.Controls.Add(txt);
data.Controls.Add(new LiteralControl("<br/>"));
}
所有文本框都将相互粘合在一起。我想知道是否可以添加填充在循环中?我该怎么办?
all textbox will be stick to each other.. I wonder can I add padding-top in the loop? how may I do it?
感谢您的帮助,您的建议和建议得到了赞赏。
thanks for your help and your suggestion and comment is appreaciated.
这是使用C#$ b创建的$ b
This is create by using C#
我希望有这样的空间。
I wish want got space like this.
请
推荐答案
我希望您对 CSS
和样式表
?
您可以在后端呈现所需的任何内容,例如您的示例:文本框。
使用CSS可以添加一些样式。
I hope you know something about CSS
and stylesheets
?You can render anything you want in the backend like in your example: textboxes.Using CSS you can add some style to it. This doesn't needs to be done during the creation of your controls.
在您的示例中,只需创建一个样式表,例如 default.css
并使用以下命令将其添加到您的网页中:
In your example just create a stylesheet like default.css
and add it into your page using:
<link rel="stylesheet" type="text/css" href="./css/default.css" />
然后使用以下代码,您可以在输入内容中添加一些填充甚至更好的边距:
Then using following code you can add some padding or even better some margin to your inputs:
input[type="text"] {
margin-bottom: 10px;
}
另一个解决方案是使用类:
Another solution is using classes:
ASP.NET
for (int x = 0; x < 30; x++)
{
TextBox txt = new TextBox();
txt.ID = "txt - " + x.ToString();
txt.CssClass = "form-control"; //Assign a css class to your textbox
data.Controls.Add(txt);
data.Controls.Add(new LiteralControl("<br/>"));
}
CSS
.form-control {
margin-bottom: 10px;
}
这篇关于将填充设置为动态文本框C#asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!