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

Update datetime in sql during Edit Mode RadGrid

2 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 28 Jul 2010, 11:10 PM
Group,
I am new to the telerik tools, and I am using the RadGrid control.  Basically I have the grid populated with data, and I have a

GridEditCommandColumn

 

.  When I click the edit button it turns any fields that aren't set to ReadOnly into editable controls (edit in place).  Two of the columns are GridDateTimeColumn(s) that when in edit mode show as what appears to look similar to a TextBox with a Date and Time Picker next to the "TextBox."

I can't for the life of me, when I select a different date or time, access the new value via c# codebehind when I click update.  Hopefully my code will help explain what I am trying to do.  This code appears in my RadGrid1_UpdateCommand

-- This works and updates my Sql database table. Basically it recognizes the text fields inside the TextBox without any problems.

            TableCell cell8 = item["RunDuration"];  --"RunDuration" is my UniqueName for that GridBoundColumn
            string _RunDuration = (cell8.Controls[0] as TextBox).Text;
            myClass.RunDuration = Convert.ToDecimal(_RunDuration);  -- I created a class in c# to handle inserts/updates

-- I can't get this to work, and I am not sure how to reference a cell that has a Datetimepicker... it doesn't appear to be a textbox, but I
-- can't figure out how to reference it.

            TableCell cell6 = item["RunStartTime"];
            RadDatePicker _StartTime = (cell6.Controls[0] as RadDatePicker);
            mfgProductionRun.StartTime = Convert.ToDateTime(_StartTime);

I get an error of: Unable to cast object of type 'Telerik.Web.UI.RadDateTimePicker' to type 'System.IConvertible'.

Any help is greatly appreciated.  I just want to be able to click the edit button, change the datetime fields if necessary and then have the new values write to the Sql database when I click update..

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jul 2010, 05:33 AM
Hello Jon,

Try the following code snippet to access the SelectedDate in RadDatePicker .

C#:
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
   {
       GridEditableItem edititem = (GridEditableItem)e.Item;
       RadDatePicker datePick = (RadDatePicker)edititem["RunStartTime"].Controls[0]; // access DatePicker
       DateTime StartTime = Convert.ToDateTime(datePick.SelectedDate);//access the Selected Date in RadDatePicker
   }

Thanks,
Princy.
0
Jon
Top achievements
Rank 1
answered on 29 Jul 2010, 03:55 PM
That did it... thanks Princy!
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or