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

radgrid with datepickercontrol

2 Answers 66 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Rathan
Top achievements
Rank 1
Rathan asked on 30 Mar 2012, 02:09 PM
Hi,


This is Rathan,


I placed the two datepickker controls inside radgrid ,i want to calculate the days between two dates using javascript.

please help me how can i get the value of datepicker control value when i selected the date from picker  for caluclating days.

forexample :
var date=document.getelementbyid('datepicker1').value; (for normal javascript)

how can i get the value of datepicker like above example.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Mar 2012, 03:31 PM
HI Rathan,

Please take a look into the following code snippet I tried to find the difference between two date in the RadDatePickers.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" >
  <MasterTableView>
    <Columns>
      <telerik:GridTemplateColumn>
        <ItemTemplate>
          <telerik:RadDatePicker ID="RadDatePicker1" runat="server"></telerik:RadDatePicker>
          <telerik:RadDatePicker ID="RadDatePicker2" runat="server"></telerik:RadDatePicker>
        </ItemTemplate>
      </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="diff" OnClientClick="OnClientClick(); return false;" />

JS:
<script type="text/javascript">
    function OnClientClick()
    {
        var grid = $find("<%=RadGrid1.ClientID%>");
        rd1 = new Date(grid.MasterTableView.get_dataItems()[0].findControl("RadDatePicker1").get_selectedDate());
        rd2 = new Date(grid.MasterTableView.get_dataItems()[0].findControl("RadDatePicker2").get_selectedDate());
        msPerDay = 24 * 60 * 60 * 1000;
        days = Math.round((rd1.valueOf() - rd2.valueOf()) / msPerDay);
        alert(days)
    }
</script>

Hope this helps,

Thanks,
Princy.
0
Eyup
Telerik team
answered on 30 Mar 2012, 03:50 PM
Hello Rathan,

I suppose this is what you are searching for:
var date = $find('<%=RadDatePicker1.ClientID %>').get_selectedDate();
Hope this helps.

All the best,
Eyup
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
Calendar
Asked by
Rathan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eyup
Telerik team
Share this question
or