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

DateTimeColumn Filter Readonly issue

4 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkat
Top achievements
Rank 1
Venkat asked on 08 Mar 2012, 03:49 PM
Hi,
i have a grid with dynamically created DateTime column. Since it was a DateTimeColumn i have datePicker  as a filter control. now the problem is that i want to restrict that filter control as read only. i tried with following code in item created

protected void grid_itemCreated(object sender, GridItemEventArgs e){
DatePicker datePicker = null;
// Code here to find GridFilterControl
datePicker.DataInput.ReadOnly = true;

above code works fine but i can not  choose date from calender popup too.  i am expecting output like user can choose date from calender popup but should not enter date from keys. Kindly suggest to solve this problem
thanks  in advance

regards
Venkat  

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Mar 2012, 07:22 AM
Hello,

Here is the sample code that I tried which worked as expected.
C#:
void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridFilteringItem)
 {
  GridFilteringItem item = (GridFilteringItem)e.Item;
  RadDatePicker txt = (RadDatePicker)item["UniqueName"].Controls[0];
  txt.DateInput.ReadOnly = true;
 }
}

Thanks,
Princy.
0
Venkat
Top achievements
Rank 1
answered on 09 Mar 2012, 08:01 AM
Hello Princy,

Thanks for your reply. i have tried your code sample but i ends with same problem. this is my exact code that i have tried

protected void grdView_ItemCreated(object sender, GridItemEventArgs e)
{
foreach (GridColumn column in grdView.Columns)
{
    if (column.UniqueName == "DOB" && e.Item is GridFilteringItem)
   {
RadDatePicker picker = ((GridFilteringItem)e.Item)["DOB"].Controls[0] as RadDatePicker;
     if (picker != null)
                 {
        picker.DateInput.DateFormat = baseCultureID;
      picker.DateInput.ReadOnly = true;
      }
 }
 }
 }

Regards
Venkat
0
Richard
Top achievements
Rank 1
answered on 12 Mar 2012, 08:53 PM
Venkat:

You can also try setting the DateInput.EnableTyping="false" as discussed in these forum threads:

readonly datepicker textbox 
Format masking / filtering in RadDatePicker

The above setting should disable the ability to type in a date in the textbox, but still allow you to pick one from the popup. When the date from the pop-up is selected, the textbox gets populated.

I tested this code and it works as expected:

foreach (GridColumn column in RadGrid1.Columns)
{
    if (column.UniqueName == "PublishDate" && e.Item is GridFilteringItem)
    {
        RadDatePicker picker = ((GridFilteringItem)e.Item)["PublishDate"].Controls[0] as RadDatePicker;
        if (picker != null)
        {
            // either of the following settings disables typing in the textbox but preserves popup calender functionality
            picker.DateInput.ReadOnly = true;
            picker.EnableTyping = false;
        }
    }
}

Hope this helps!
0
Venkat
Top achievements
Rank 1
answered on 13 Mar 2012, 04:30 AM
Hello,
Thanks for your reply. your code works fine and reached my expectation. thanks again

regards
Venkat
Tags
Grid
Asked by
Venkat
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Venkat
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Share this question
or