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

1

本文介绍了将填充设置为动态文本框 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14