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

RadDatePicker event in RadGrid

6 Answers 477 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeyaganesh T
Top achievements
Rank 1
Jeyaganesh T asked on 03 Sep 2010, 08:55 AM
Hello,
We use RadGrid to populate 2500 rows from the DB with a gridtemplatecolumn containing a RadDatePicker with name "dtpStart"
How do we trigger the RadDatePicker event, when it is changed so that we change a value of other Datepicker in the same row..

Need Solution......Thanks

6 Answers, 1 is accepted

Sort by
0
Prangadj
Top achievements
Rank 1
answered on 03 Sep 2010, 10:06 AM
Jayaganesh, I create sites with Telerik Ajax and use this demo in my scenario:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

When I have date pickers and not combos, I listen for SelectedDateChanged event of the first picker and change the value in the other in the row inside the select date handler as before.

Hope I am helpful,
Prangadj
0
Jeyaganesh T
Top achievements
Rank 1
answered on 03 Sep 2010, 11:01 AM
Hi,

The link show and works in the edit mode....in my case the datepicker's are in the cell directly,i change that without clicking edit 

Since more changes will occur at a time where i can't keep editing each row seperately...
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Sep 2010, 11:03 AM
Hello Jayaganesh,

As Prangadj mentioned in the previous reply, you can achieve this by attaching OnSelectedDateChanged event to RadDatePicker. In the event handler, access the data item using NamingContainer property of RadDatePicker and then access the other DatePicker using FindControl() method.

Here is the code details:

ASPX:
<telerik:GridTemplateColumn>
   <ItemTemplate>
      <telerik:RadDatePicker ID="RadDatePicker1" runat="server" OnSelectedDateChanged="RadDatePicker1_SelectedDateChanged">
      </telerik:RadDatePicker>
   </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
  {
      RadDatePicker datePicker1 = (RadDatePicker)sender;
      GridDataItem item = (GridDataItem)datePicker1.NamingContainer;
      RadDatePicker datePicker2 = (RadDatePicker)item.FindControl("RadDatePicker2"); //accessing other RadDatePicker
  }

Thanks,
Princy.
0
Jeyaganesh T
Top achievements
Rank 1
answered on 03 Sep 2010, 12:53 PM
Thanks Princy.....It Works
0
raghu
Top achievements
Rank 1
answered on 21 Apr 2016, 09:39 AM

Hi Princy,

<Columns>
                            <telerik:GridBoundColumn UniqueName="Task_ID" DataField="Task_ID" HeaderText="Task ID"
                                HeaderStyle-Width="50px" />
                            <telerik:GridBoundColumn DataField="Task_Name" HeaderText="Task Name" HeaderStyle-Width="200px" />
                            <telerik:GridBoundColumn DataField="Estimated_Duration" HeaderText="Estimated_Duration"
                                HeaderStyle-Width="100px" />
                            <telerik:GridTemplateColumn HeaderText="Start" UniqueName="Start">
                                <ItemTemplate>
                                    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" AutoPostBack="true" OnSelectedDateChanged="RadDatePicker1_OnSelectedDateChanged">
                                    </telerik:RadDatePicker>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Finish" UniqueName="Finish">
                                <ItemTemplate>
                                    <telerik:RadDatePicker ID="RadDatePicker2" runat="server">
                                    </telerik:RadDatePicker>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>

how to get Estimated_Duration (third column) value from RadDatePicker1_OnSelectedDateChanged (same row)

Best Regards

Raghu

0
Eyup
Telerik team
answered on 26 Apr 2016, 08:58 AM
Hi Raghu,

You can use the following approach to achieve this requirement:
protected void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
    RadDatePicker picker = sender as RadDatePicker;
    GridDataItem item = picker.NamingContainer as GridDataItem;
    TableCell cell = item["Estimated_Duration"];
 
    string value = cell.Text;
    DateTime dateValue;
    if (DateTime.TryParse(value, out dateValue))
    {
        // execute custom logic with the date
    }
}

I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
General Discussions
Asked by
Jeyaganesh T
Top achievements
Rank 1
Answers by
Prangadj
Top achievements
Rank 1
Jeyaganesh T
Top achievements
Rank 1
Princy
Top achievements
Rank 2
raghu
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or