将填充设置为动态文本框 C# asp.net

set padding to dynamic textbox C# asp.net(将填充设置为动态文本框 C# asp.net)
本文介绍了将填充设置为动态文本框 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)