Cell not inset if blank

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

If you have nothing in a cell, the cell doesn't have the inset appearance
that all the other cells do.

Normally, you could just put a "&ndsp;" in the cell if the it is blank.

But how do you do this if you are binding it?

<asp:TemplateColumn Visible="true" HeaderText="JobTitle"
ItemStyle-Font-Bold="true"
ItemStyle-Width="195px" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Label ID="JobTitle" Text='<%#
Container.DataItem("JobTitleShort")%>' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>

Is there a way to say that if the cell is blank (or null entry), to put an
"&ndsp;" in it (or something that would fix the inset problem)?

Thanks,

Tom
 
Did you test it to observe that the "&nbsp;" is not there? I think, Asp.Net
takes care about it and does put a "&nbsp;" character in empty cells.

Eliyahu
 
Eliyahu Goldin said:
Did you test it to observe that the "&nbsp;" is not there? I think, Asp.Net
takes care about it and does put a "&nbsp;" character in empty cells.

If it does, I assume that there must be some setting to make it do that.

Here is one row from my Datagrid:

<td valign="Top" style="font-weight:bold;width:195px;">
<span id="InProgressGrid__ctl2_JobTitle">Assistant Controller</span>
</td><td valign="Top" style="width:231px;">
<span id="InProgressGrid__ctl2_Category">Accounting/Auditing </span>
</td><td valign="Top" style="width:88px;">
<span id="InProgressGrid__ctl2_DateCreated">06/16/2005</span>
</td><td valign="Top" style="width:70px;">
<span id="InProgressGrid__ctl2_TimeCreated">12:00AM</span>
</td><td valign="Top" style="width:167px;">
<span id="InProgressGrid__ctl2_FullName"></span>
<-------
</td><td class="tdCenter" valign="Top" style="width:40px;">
<input type="image" name="InProgressGrid:_ctl2:ViewButton"
id="InProgressGrid__ctl2_ViewButton" align="absmiddle"
src="../../images/new24-32.gif" alt="" border="0"
style="height:13px;width:13px;" />
</td>

As you can see, it creates Spans for each cell. But if you look at the
FullName Span, there is nothing between the spans.

Tom
 
The cell is not blank. It has a <span> inside, that's why asp.net doesn'
produce an "&nbsp;".

Replace the Label with a Literal and the <span> will go:

<itemtemplate>
<asp:Literal ID="JobTitle" Text='<%# Container.DataItem("JobTitleShort")%>'
runat="server" />
</itemtemplate>

Eliyahu
 
Eliyahu Goldin said:
The cell is not blank. It has a <span> inside, that's why asp.net doesn'
produce an "&nbsp;".

Replace the Label with a Literal and the <span> will go:

<itemtemplate>
<asp:Literal ID="JobTitle" Text='<%#
Container.DataItem("JobTitleShort")%>' runat="server" />
</itemtemplate>

I tried that and the span does go away, but the code generated for a null is
still blank. Here is the code generated. All 3 are Literals but there is
no &nbsp; in the last 2 which are null, so the cell doesn't show correctly.

</td><td valign="Top" style="width:231px;">
Aerospace/Aviation/Defense
</td><td valign="Top" style="width:88px;">

</td><td valign="Top" style="width:70px;">

</td><td valign="Top" style="width:167px;">

Here is the asp code for the 3 templates:

<asp:TemplateColumn Visible="true" HeaderText="Category"
ItemStyle-Width="231px" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Literal ID="Category" Text='<%#
Container.DataItem("JobCategories")%>' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="true" HeaderText="Submitted On"
ItemStyle-Width="88px" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Literal ID="DateCreated" Text='<%#
Container.DataItem("DateCreated")%>' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="true" HeaderText="Time"
HeaderStyle-Font-Underline="true" ItemStyle-Width="70px"
ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Literal ID="TimeCreated" Text='<%#
Container.DataItem("TimeCreated")%>' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>

Do I need to do something to put the &nbsp; in?

Tom
 
You can always use PreRender event to loop through the items, check if the
literals are empty and set them to "&nbsp;"

Eliyahu
 
I could.

I was just looking for a way around this.

I have a page that has 6 Datagrids and it would add a little more processing
to do this. I was hoping there was a way to do, as you mentioned with the
Literal object, which would have been a good way to solve the problem.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top