format grid control

Mark Elliott asked on October 17, 2014 18:02

Is there a way to format the columns in the grid control? We are displaying a date field on the grid and only want to show the date not the time.

Thanks

Correct Answer

Pavel Janečka answered on October 22, 2014 15:54

Sorry, I did not realize that, in this case I found out only the hack that leverages including the following code in your selected columns: CONVERT(nvarchar(20), [yourdatetimecolumn], 107) AS DateOnly

0 votesVote for this answer Unmark Correct answer

Recent Answers


Pavel Janečka answered on October 21, 2014 10:06

Hi Mark, you can create a custom transformation and change the column formatting there. For example, with the ASCX transformation you could use the following code: <%# ((DateTime)Eval("YourDateTimeColumn")).ToShortDateString() %>

0 votesVote for this answer Mark as a Correct answer

Mark Elliott answered on October 21, 2014 22:50

I don't see where this transformation would be applied. The grid only has a Selected item transformation for the detail view of the item.

0 votesVote for this answer Mark as a Correct answer

Mark Elliott answered on October 22, 2014 18:22

I changed the grid to a querydatagrid and put the convert statement in the query and that did the trick. Still think its a bit silly cant format the selected columns through the interface.

0 votesVote for this answer Mark as a Correct answer

Pavel Janečka answered on October 25, 2014 18:28

Seems funny to me, too. I will ask around the office if there's a better solution once I'm at work :)

0 votesVote for this answer Mark as a Correct answer

Pavel Janečka answered on December 1, 2014 09:55

Hey Mark,
so I've talked about this with my colleagues and we regrettably found out that there is currently no other way around that.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.