RadDatePicker event in RadGrid

7 posts, 1 answers
  1. Jeyaganesh T
    Jeyaganesh T avatar
    7 posts
    Member since:
    May 2010

    Posted 03 Sep 2010 Link to this post

    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
  2. Prangadj
    Prangadj avatar
    174 posts
    Member since:
    Jan 2008

    Posted 03 Sep 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeyaganesh T
    Jeyaganesh T avatar
    7 posts
    Member since:
    May 2010

    Posted 03 Sep 2010 Link to this post

    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...
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2010 Link to this post

    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.
  6. Jeyaganesh T
    Jeyaganesh T avatar
    7 posts
    Member since:
    May 2010

    Posted 03 Sep 2010 Link to this post

    Thanks Princy.....It Works
  7. raghu
    raghu avatar
    5 posts
    Member since:
    Feb 2016

    Posted 21 Apr in reply to Jeyaganesh T Link to this post

    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

  8. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 26 Apr Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017