I have a RadGrid with two date columns and I have added a Calculated Column to get the number of days between them.
I tried a couple of techniques I found from Google to display the number of days but it always displays in this format: 2.00:00:00 for two days. Fourty days looks like 40.00:00:00. I just want to display the number of days as an integer like, "2" or "40".
The Calculated column UniqueName="DaysOpen".
One of the techniques I tried did the calculation in the .vb file and was supposed to send the value to a GridTemplateColumn with a <asp:Label /> in the ItemTemplate, but that method didn't work at all. The column showed no values at all. The column was there but all the fields were blank.
.aspx
.aspx.vb - I commented out both methods because neither of them seemed to do anything. In or out made no difference to the grid contents at all like they just weren't accessing the grid objects, which is probably the case. On line 27 I hard coded a "3" in place of the now commented out, [date].ToString and the column was still blank.
With my markup and code just as above the DaysOpen column displayes the correct number of days, just in the long format. I just want to display it as an integer. e.g. "40" not "40.00:00:00"
Thank you!
I tried a couple of techniques I found from Google to display the number of days but it always displays in this format: 2.00:00:00 for two days. Fourty days looks like 40.00:00:00. I just want to display the number of days as an integer like, "2" or "40".
The Calculated column UniqueName="DaysOpen".
One of the techniques I tried did the calculation in the .vb file and was supposed to send the value to a GridTemplateColumn with a <asp:Label /> in the ItemTemplate, but that method didn't work at all. The column showed no values at all. The column was there but all the fields were blank.
.aspx
<
telerik:GridCalculatedColumn
DataFields
=
"DateResolved,DateReceived"
Expression
=
"{0}-{1}"
headerstyle-width
=
"50px"
HeaderText
=
"Days Open"
UniqueName
=
"DaysOpen"
Aggregate
=
"None"
>
</
telerik:GridCalculatedColumn
>
<%--
<
telerik:GridTemplateColumn
UniqueName
=
"Temp"
HeaderStyle-Width
=
"50px"
HeaderText
=
"days open"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"DaysOpen"
runat
=
"server"
></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
--%>
.aspx.vb - I commented out both methods because neither of them seemed to do anything. In or out made no difference to the grid contents at all like they just weren't accessing the grid objects, which is probably the case. On line 27 I hard coded a "3" in place of the now commented out, [date].ToString and the column was still blank.
Imports
Telerik.Web.UI
Partial
Class
test
Inherits
System.Web.UI.Page
'Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
' 'grid.MasterTableView.SwapColumns("ComplaintID", "DateReceived")
'End Sub
'Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
' If TypeOf e.Item Is GridDataItem Then
' Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
' Dim myTS As TimeSpan = TimeSpan.Parse(item("DaysOpen").Text)
' item("DaysOpen").Text = [String].Format("{0}h {1}m {2}s", myTS.Days, myTS.Hours, myTS.Minutes)
' End If
'End Sub
' Both methods of getting the difference between two dates work equally well.
' Actually neither of them seem to do shit. When I commented them both out I still got the same correct results, but formatted like this: 2.00:00:00 for two days.
'Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
' If TypeOf e.Item Is GridDataItem Then
' Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
' Dim DaysOpen As Label = TryCast(item.FindControl("DaysOpen"), Label)
' Dim DateResolved As String = (item("DateResolved").Text)
' Dim DateReceived As String = (item("DateReceived").Text)
' Dim [date] As Integer = Convert.ToDateTime(DateResolved).Subtract(Convert.ToDateTime(DateReceived)).Days
' DaysOpen.Text = "3" ' [date].ToString()
' End If
'End Sub
End
Class
With my markup and code just as above the DaysOpen column displayes the correct number of days, just in the long format. I just want to display it as an integer. e.g. "40" not "40.00:00:00"
Thank you!