将填充设置为动态文本框 C# asp.net [英] set padding to dynamic textbox C# asp.net

查看:16
本文介绍了将填充设置为动态文本框 C# asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我从 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.

推荐答案

希望你对CSSstylesheets有所了解?你可以在后端渲染任何你想要的东西,比如你的例子:文本框.使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆