I have a chunk of code that on page load with populates some of or all of the following labels. It should have two labels per line ( needs a line break after each xData label). The problem I am having is that since the number of labels with data and set to visable on page load changes, the br /
tags cause spacing issues when not all labels are visible.
我有一大堆代码在页面加载时填充以下部分或全部标签。它应该每行有两个标签(每个xData标签后需要一个换行符)。我遇到的问题是,由于带有数据且设置为在页面加载时可见的标签数量发生变化,因此当并非所有标签都可见时,br /标签会导致间距问题。
<div id="Status">
<asp:Label ID="1" runat="server" Text="1:" Width="125px" Visible="false" />
<asp:Label ID="1Data" runat="server" Text="" Visible="false" />
<asp:Label ID="2" runat="server" Text="2:" Width="125px" Visible="false" />
<asp:Label ID="2Data" runat="server" Text="" Visible="false" />
<asp:Label ID="3" runat="server" Text="3:" Width="125px" Visible="false" />
<asp:Label ID="3Data" runat="server" Text="" Visible="false" />
</div>
I would like to be able to add the line breaks after each "xData" label in the code behind when the labels are filled and set to visible.
我希望能够在标签填充并设置为可见时在后面的代码中的每个“xData”标签后添加换行符。
I have tried adding "\n"
to the label text and\or Environment.NewLine
with no luck.
我试过在标签文本和\或Environment.NewLine中添加“\ n”而没有运气。
Thanks for any help
谢谢你的帮助
6 个解决方案
#1
2
The easy way...
简单的方法......
<div id="Status">
<div id="Status1" runat="server" Visible="false">
<asp:Label ID="1" runat="server" Text="1:" Width="125px" />
<asp:Label ID="1Data" runat="server" Text="" />
</div>
<div id="Status2" runat="server" Visible="false">
<asp:Label ID="2" runat="server" Text="2:" Width="125px" />
<asp:Label ID="2Data" runat="server" Text="" />
</div>
<div id="Status3" runat="server" Visible="false">
<asp:Label ID="3" runat="server" Text="2:" Width="125px" />
<asp:Label ID="3Data" runat="server" Text="" />
</div>
</div>
The right way...
正确的方式...
<div id="Status">
<asp:Label CssClass="statusLabel" ID="1" runat="server" Text="1:" Width="125px" Visible="false" />
<asp:Label ID="1Data" runat="server" Text="" Visible="false" />
<asp:Label CssClass="statusLabel" ID="2" runat="server" Text="2:" Width="125px" Visible="false" />
<asp:Label ID="2Data" runat="server" Text="" Visible="false" />
<asp:Label CssClass="statusLabel" ID="3" runat="server" Text="3:" Width="125px" Visible="false" />
<asp:Label ID="3Data" runat="server" Text="" Visible="false" />
</div>
/* CSS */
#Status span {
display: block;
}
#Status .statusLabel {
clear: both;
float: left;
}
#2
1
I think you could do it a couple of different ways.
我想你可以通过几种不同的方式做到这一点。
One option would be what @Greg points out in his comment to your post.
一个选择是@Greg在他对你的帖子的评论中指出的。
Another possible option would be enclosing each label in its own <div>
tag with runat="server"
and then make these <div>
s visible when needed. The <div>
should create its own line break because of the nature of a <div>
另一种可能的选择是将每个标签用runat =“server”封装在自己的
#3
1
asp:Label resolves to a span in html. If you want each one to have its own line, add the css style "display:block". Usually, you can do this by setting CssClass and put display:block in that class
asp:Label解析为html中的span。如果您希望每个人都有自己的行,请添加css样式“display:block”。通常,您可以通过设置CssClass并在该类中放置display:block来完成此操作
#4
1
If you want this way, you need to use Literal control for each BR tag so that you can set it to visible/invisible based on the visibility of corresponding Label control.
如果您需要这种方式,则需要对每个BR标记使用Literal控件,以便根据相应Label控件的可见性将其设置为可见/不可见。
#5
1
Why not just add a CSS class with a display: block
rule to those labels?
为什么不直接添加带有display:block规则的CSS类到这些标签?
This is presentational, after all.
毕竟,这是表现性的。
#6
0
Try wrapping the labels around a <div>
instead of putting a <br />
at the end. In my experience, empty <div>
's don't create that empty space.
尝试将标签包裹在
。根据我的经验,空
#1
2
The easy way...
简单的方法......
<div id="Status">
<div id="Status1" runat="server" Visible="false">
<asp:Label ID="1" runat="server" Text="1:" Width="125px" />
<asp:Label ID="1Data" runat="server" Text="" />
</div>
<div id="Status2" runat="server" Visible="false">
<asp:Label ID="2" runat="server" Text="2:" Width="125px" />
<asp:Label ID="2Data" runat="server" Text="" />
</div>
<div id="Status3" runat="server" Visible="false">
<asp:Label ID="3" runat="server" Text="2:" Width="125px" />
<asp:Label ID="3Data" runat="server" Text="" />
</div>
</div>
The right way...
正确的方式...
<div id="Status">
<asp:Label CssClass="statusLabel" ID="1" runat="server" Text="1:" Width="125px" Visible="false" />
<asp:Label ID="1Data" runat="server" Text="" Visible="false" />
<asp:Label CssClass="statusLabel" ID="2" runat="server" Text="2:" Width="125px" Visible="false" />
<asp:Label ID="2Data" runat="server" Text="" Visible="false" />
<asp:Label CssClass="statusLabel" ID="3" runat="server" Text="3:" Width="125px" Visible="false" />
<asp:Label ID="3Data" runat="server" Text="" Visible="false" />
</div>
/* CSS */
#Status span {
display: block;
}
#Status .statusLabel {
clear: both;
float: left;
}
#2
1
I think you could do it a couple of different ways.
我想你可以通过几种不同的方式做到这一点。
One option would be what @Greg points out in his comment to your post.
一个选择是@Greg在他对你的帖子的评论中指出的。
Another possible option would be enclosing each label in its own <div>
tag with runat="server"
and then make these <div>
s visible when needed. The <div>
should create its own line break because of the nature of a <div>
另一种可能的选择是将每个标签用runat =“server”封装在自己的
#3
1
asp:Label resolves to a span in html. If you want each one to have its own line, add the css style "display:block". Usually, you can do this by setting CssClass and put display:block in that class
asp:Label解析为html中的span。如果您希望每个人都有自己的行,请添加css样式“display:block”。通常,您可以通过设置CssClass并在该类中放置display:block来完成此操作
#4
1
If you want this way, you need to use Literal control for each BR tag so that you can set it to visible/invisible based on the visibility of corresponding Label control.
如果您需要这种方式,则需要对每个BR标记使用Literal控件,以便根据相应Label控件的可见性将其设置为可见/不可见。
#5
1
Why not just add a CSS class with a display: block
rule to those labels?
为什么不直接添加带有display:block规则的CSS类到这些标签?
This is presentational, after all.
毕竟,这是表现性的。
#6
0
Try wrapping the labels around a <div>
instead of putting a <br />
at the end. In my experience, empty <div>
's don't create that empty space.
尝试将标签包裹在
。根据我的经验,空