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

Grid : Date Picker

3 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Janaki
Top achievements
Rank 1
Janaki asked on 11 Jul 2012, 09:27 AM
Hi all,

In my datagrid, I need to generate an automatic date picker on the addnewrecord command. How can I do this?

Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Jul 2012, 09:45 AM
Hello Janaki,

You can add a DatePicker dynamically using the following code.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditFormInsertItem )
 {
    GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
    RadDatePicker pkr = new RadDatePicker();
    pkr.ID = "RadDatePicker1";
    item["UniqueName"].Controls.Add(pkr);
  }
}

Thanks,
Princy.
0
Franklin
Top achievements
Rank 1
answered on 13 Jul 2012, 04:12 PM
Hi Princy!
I´ve got a treelist with two datepickers added dynamically when I am going to insert a new row

How can I validate when press the save button inside the treelist, the date selected in the first fileld is minor than the second one?
and show the appropriate error message?

Thanks,
Franklin.
0
Princy
Top achievements
Rank 2
answered on 16 Jul 2012, 06:29 AM
Hello Franklin,

You can use CompareValidator for comparing the dates. Here is the sample code.
C#:
protected void RadTreeList1_ItemCreated(object sender, Telerik.Web.UI.TreeListItemCreatedEventArgs e)
{
 if (e.Item is TreeListDataInsertItem)
 {
   TreeListDataInsertItem item = (TreeListDataInsertItem)e.Item;
   CompareValidator com = new CompareValidator();
   com.ID = "CompareValidator1";
   item["ColumnUniqueName"].Controls.Add(com);
   RadDatePicker pkr1 = new RadDatePicker();
   pkr1.ID = "RadDatePicker1";
   item["ColumnUniqueName"].Controls.Add(pkr1);
   RadDatePicker pkr2 = new RadDatePicker();
   pkr2.ID = "RadDatePicker2";
   item["ColumnUniqueName1"].Controls.Add(pkr2);
   RadDatePicker picker1 = (RadDatePicker)item.FindControl("RadDatePicker1");
   RadDatePicker picker2 = (RadDatePicker)item.FindControl("RadDatePicker2");
   DateTime startDate = Convert.ToDateTime(pkr1.SelectedDate);
   CompareValidator compValidate = (CompareValidator)item.FindControl("CompareValidator1");
   compValidate.ControlToValidate =picker1.ID;
   compValidate.ControlToCompare = picker2.ID;
   compValidate.ValueToCompare = DateTime.Now.ToShortDateString();
   compValidate.Type = ValidationDataType.Date;
   compValidate.Operator = ValidationCompareOperator.LessThanEqual;
   compValidate.ErrorMessage = "EndDate should not be less than StartDate"
 }
}

Thanks,
Princy.
Tags
Grid
Asked by
Janaki
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Franklin
Top achievements
Rank 1
Share this question
or