问题描述
这是我从 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/>"));
}
所有文本框都将相互粘连.我想知道我可以在循环中添加 padding-top 吗?我该怎么做?
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# 创建的
This is create by using C#
我希望有这样的空间.
请忽略下拉框.它只是示例.
please ignore the drop down box.. its just example.
推荐答案
希望你对CSS
和stylesheets
有所了解?你可以在后端渲染任何你想要的东西,比如你的例子:文本框.使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!