ASP.NET Datagrid - hiding a specific row / column

I am using a Datagrid with multiple data columns (call it myDG) and one of those columns is bound to a DateTime to the data source. Its meaning depends on the "job" object running the job and the purpose of the date time value. Since this usually takes up to a minute, the value remains unassigned at the beginning.

Asp.net column definition:

<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" is complete and it sets the time. But before that, while the string is displayed, it is displayed as

01-Jan-0001 12:00:00 AM

I want to hide this and figured that the best way would be to hide this specific row and column with a space, or override the value temporarily. I am having problems with this and finding a way to access this particular row and column.

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

Is there a way to directly access this cell and temporarily "hide" or mask its contents? Ideally, it would be great if there was a way to skip all rows that had a value equal to that in their column, but a way to manipulate a specific cell would also work.

-thanks in advance!

0


source to share


3 answers


I've done similar things in the past and here's what I did.



Bind data to a column that is not displayed at all. Add a visible column for the data you want to display. At the time you fill in your grid, scroll through the entries and for those with a value that is not 01-Jan-0001 12:00:00 AM, set your visible row to that value. If it is 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 can even set the text color to be the same as the background color so that it doesn't show up to the user)

0


source


I would probably intercept OnItemDataBound, check the value, and replace / format as needed.



+2


source


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 that might help you as well (especially with hidden data columns).

+2


source







All Articles