开发者

Table borders when no data in cell

开发者 https://www.devze.com 2023-02-10 13:24 出处:网络
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\">

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 开发者_如何学Goknow 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:

<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.


This question is about the same issue, Internet Explorer not rendering empty cells.


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;:

<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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消