This is a migrated thread and some comments may be shown as answers.

OADate column

3 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 2
Phil asked on 04 Nov 2011, 06:09 PM
Hi:
I have 2 columns that are OADate type (per RadChart).  How do I format it in a data bound column?  The column appear as a #, and when I try to set the FormatString as a date then it throws an exception.
Phil
p.s. Telerik opened pandora's box in RadChart.

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 09 Nov 2011, 08:09 AM
Hi Phil,

Is the issue you are facing with RadGrid or RadChart? What is the error message you see? Can you share the problematic columns declaration and elaborate on what you expect to see there?

Best wishes,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Phil
Top achievements
Rank 2
answered on 12 Nov 2011, 01:15 AM
Hi
Sample
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="Telerik" %>
<script runat="server">
    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime DOB { get; set; }
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!(IsPostBack)) {
            var _list = new List<Person>()
            {
                new Person {FirstName = "One", LastName = "Person", DOB = DateTime.Parse("1980-01-01")},
                new Person {FirstName = "Two", LastName = "Person", DOB = DateTime.Parse("1976-07-04")}
            };
            dateGrid.DataSource = (from _l in _list
                select new { DOB = _l.DOB.ToOADate(), FirstName = _l.FirstName, LastName = _l.LastName });
            dateGrid.DataBind();
        }
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <telerik:radgrid ID="dateGrid" runat="server" AutoGenerateColumns="False">
        <MasterTableView DataKeyNames="LastName">
            <Columns>
                <Telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstNameColumn" HeaderText="First Name" />
                <Telerik:GridBoundColumn DataField="LastName" UniqueName="LastNameColumn" HeaderText="Last Name" />
                <Telerik:GridBoundColumn DataField="DOB" UniqueName="DOBColumn" HeaderText="DOB" />
            </Columns>
        </MasterTableView>
    </telerik:radgrid>
</asp:Content>
The dates are displayed as 29221 & 27945.  I have a chart that I am also placing the supporting data is a grid.
Phil
0
Iana Tsolova
Telerik team
answered on 14 Nov 2011, 12:24 PM
Hello Phil,

I tested your code and I find the behavior you describe as expected. To further prove it I added a label to the page and set its text to the same value as in the grid column:
<asp:Label ID="Label1" runat="server" />
protected void Page_Load(object sender, System.EventArgs e)
{
    if (!(IsPostBack))
    {
        var _list = new List<Person>()
        {
            new Person {FirstName = "One", LastName = "Person", DOB = DateTime.Parse("1980-01-01")},
            new Person {FirstName = "Two", LastName = "Person", DOB = DateTime.Parse("1976-07-04")}
        };
        dateGrid.DataSource = (from _l in _list
                               select new { DOB = _l.DOB.ToOADate(), FirstName = _l.FirstName, LastName = _l.LastName });
        dateGrid.DataBind();
 
        Label1.Text = _list[0].DOB.ToOADate().ToString();
    }
}

As a result the text displayed in the label was the same as this for the DOB column for the first row in the grid.

Can you elaborate on what is the desired effect and what you are trying to achieve?

Kind regards,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Phil
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Phil
Top achievements
Rank 2
Share this question
or