1

I have a Telerik radgrid textbox that stores date value. On update of the grid for the date I get an issue. Can anyone help me regarding this. I tried DateTime.TryParse ,Convert.Datatime... But nothing worked..

<telerik:GridBoundColumn DataField="DTTM" 
    HeaderText="Date Registered" SortExpression="DTTM" UniqueName="DTTM">
</telerik:GridBoundColumn>

On update:

updhost.DTTM=ShowDate((RadTextBox)editedItem.FindControl("DtB"));

ShowDate()

private string ShowDate(object datVal)
{
    string newStr = "";
    DateTime tmpDttm = default(DateTime);
    if ((datVal != null)) 
    {
        try 
        {
            tmpDttm = (DateTime)datVal;
            newStr = tmpDttm.ToString("MM/dd/yyyy h:mm tt") + " ";
        } 
        catch (Exception ex) {
            //Do Nothing
        }
    }
    return newStr;
}
mnwsmit
  • 1,198
  • 2
  • 15
  • 31
vana
  • 13
  • 1
  • 6
  • You're trying to cast a control to a date. That's not going to work. I don't know this library in particular, but I would imagine it has something like `.Value`. Also, change your method to be `private string ShowDate(RadTextBox datVal)`. You know it's going to be a `RadTextBox`, so there's no reason to take an object parameter. – Rob Mar 11 '16 at 00:19
  • After changing it to private string ShowDate(RadTextBox datVal) it giving me an error in the method as cannot convert Type telrick.web.ui.radtextbox to 'System.DateTime' and i dont see any <.value> options – vana Mar 11 '16 at 00:23
  • Yes, as I said, you cannot convert a *control* to a *date*. You might be able to convert the control's *value*, but not the control itself. You might have to look at the documentation for `radgrid`, or check out the available properties/methods in `RadTextBox`. I mentioned above, it would likely have a `.Value` field which you would need to parse or cast to a date. – Rob Mar 11 '16 at 00:24

0 Answers0