简体   繁体   English

当单元格中没有数据时表格边框

[英]Table borders when no data in cell

I have a table that has a couple of cells that do not contain data: 我有一个表,其中有几个不包含数据的单元格:

<table id="table_id2" CellPadding="0" CellSpacing="0" border="1">
 <tr style="background-color:#D1DEB6"><td>Test 1</td><td class="y_n">Y</td></tr>
 <tr style="background-color:#C7D6A7"><td>Test 2</td><td class="y_n">N</td></tr>
 <tr style="background-color:#D1DEB6"><td></td><td class="y_n">Y</td></tr>
 <tr style="background-color:#C7D6A7"><td></td><td class="y_n">Y</td></tr>
</table>

I you look carefully you'll notice the borders are inconsistant. 我仔细查看后会发现边界不一致。 The borders appear but not for the cells without any data in them. 出现边框,但不显示没有任何数据的单元格的边框。 Does anyone know a solution to this? 有人知道解决方案吗? I know you can put a &nbsp in to get the borders but this isn't an option for me the reason being that some cell have labels in them like: 我知道您可以放入&nbsp来获得边框,但这对我来说不是一个选择,原因是某些单元格中带有标签,例如:

<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' />

It's causing problems when say the Name is null then I'm missing the borders for the empty cell. 当说名称为null时,这会引起问题,然后我错过了空单元格的边框。

此问题与同一问题有关,Internet Explorer不会呈现空白单元格。

If you don't want to mess with CSS you could wrap your Eval call in a formatting function from your code behind page to check for an empty string and then return a &nbsp; 如果您不想弄乱CSS,可以将Eval调用包装在页面后面的代码中的格式化函数中,以检查是否为空字符串,然后返回&nbsp; :

<asp:Label ID="Label2" runat="server" Text='<%# InsertNBSP(Eval("Name")) %>' />

On code behind: 关于后面的代码:

public string InsertNBSP(string str)
{
    if(str == "")
       return "&nbsp;"
    else
       return str;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM