views:

1500

answers:

4

I am using a Datagrid with several columns of data (call it myDG) and one of these columns is a DateTime bound to a datasource. Its value is dependent on a "job" object completing a job and assigning the date time value. Since this normally takes up to a minute the value is left unassigned at the beginning.

The column's asp.net definition is:

<asp:boundcolumn 
  DataField="CompletedDate" 
  HeaderText="Date Completed" 
  DataFormatString="{0:dd-MMM-yyyy <br> hh:mm:ss tt}" />

So the functionality works fine when the "job" has completed and it sets the time. But before that, while the row is being displayed, it shows as

01-Jan-0001 12:00:00 AM

I am wanting to hide this and determined that the best way would be to mask that particular row and column with a blank, or override the value temporarily. I am having problems doing this and finding a way to access that specific row and column.

It is the [3] column of the datagrid and always in the first row (since new rows are added at the top).

Is there a way to directly access this cell and temporarily 'hide' its contents, or mask them? Ideally it would be great if there was a way to blank out all rows that had a value equal to this in their column, but a way to manipulate the specific cell would work as well.

-thanks in advance!

A: 

sorry, the column definition got messed up... here it is... (with brackets removed)

ASP:BOUNDCOLUMN DataField="CompletedDate" HeaderText="Date Completed" DataFormatString="{0:dd-MMM-yyyy
hh:mm:ss tt}" /ASP:BOUNDCOLUMN

n2009
You can delete this, I've fixed your code formatting. To use this, hightlight the code then click the 1101 code button.
Kev
+2  A: 

I would probably hook OnItemDataBound, check the value, and replace/reformat if required.

Steven Robbins
A: 

I have done similar things in the past and here is what I have done.

Bind the data to a column that is not visible at all. Add a visible column for the data you wish to display. At the time you populate your grid, loop through the records and for any that have a value that isn't 01-Jan-0001 12:00:00 AM, set your visible row to that value. If it does equal 01-Jan-0001 12:00:00 AM, then set the value of your visible row to an empty string or some value of your choice. (You could even set the text color to the same as the background color so it wouldn't appear to the user)

Eppz
+1  A: 

I asked a similar question about hiding columns here.

I had to use the RowCreated event to hide certain columns from the user (PK columns) and this may help you out as well (especially with hiding databound columns).

Austin Salonen