is not generated for null values when using a format string

  • Thread starter Douglas J. Badin
  • Start date
D

Douglas J. Badin

I have a DataGrid with which formats dates

<ASP:TEMPLATECOLUMN SortExpression="EST_DATE" HeaderText="Est Date">
<ITEMTEMPLATE>
<ASP:LABEL runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.EST_DATE", "{0:d}") %>'></ASP:LABEL>
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>

If the value is null, a &nbsp is not generated, hence in Netscape the table
cell is no rendered correctly.

The only workaround I have found is to use the ?: operator or call a
procedure to check for "" and replace it with "&nbsp;" like:

EmptyStringCheck(DataBinder.Eval(Container, "DataItem.EST_DATE", "{0:d}"))


1. Is there a way to make the DataGrid do this like it does when a
formatting is not used?

2. Is there a conditional formatString that if "" then "&nbsp;", like the ?:
operator?

3. I tried checking in PreRender, but the TableCell.Text was still "" for
null and non-null values. So when does Formatting take place in the control
life cycle?

WindowsForms has a NullText property but I couldn't find something similar
for WebForms.

Thanks,

Doug
 
J

Jeffrey Tan[MSFT]

Hi Douglas,

Thanks for posting in this group.
Does your application work well on IE client?
As you state, you can workaround this through "?:" operator which judges
null and generates &nbsp;.
I think it should work well. What is the problem of your workaround?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
D

Douglas J. Badin

Hi Jeffrey,

The application does work well on IE. The problem is with Netscape.

The problem with the workaround is it is a workaround. I am looking for a
better solution, hopefully something built-in.

I am still looking for answers to these questions:

1. Is there a way to make the DataGrid do this like it does when a
formatting is not used?

2. Is there a conditional formatString that if "" then "&nbsp;", like the ?:
operator?

3. I tried checking in PreRender, but the TableCell.Text was still "" for
null and non-null values. So when does Formatting take place in the control
life cycle?

Thanks,
Doug
 
J

Jeffrey Tan[MSFT]

Hi Douglas,

Asp.net will judge the client browser's type and generate different html
code for client.
To customize the formatString yourself, I think you should do different
customize on different object type(Because formatstring will take effect on
different types)
You can find how to customize formatstring for custom types or Existing
types from the article below:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcustomizingformatstrings.asp

If you want to determine the time asp.net parse formatstring, you can
override OnPreRender, RenderControl, RenderChildren, Render method to see
in which method the content changes

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top