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

How to apply Mindate Property to GridDateTimeColumn in radgrid

4 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vinod
Top achievements
Rank 1
vinod asked on 07 Oct 2008, 07:09 AM
Hello All,

Can we apply Mindate Property to GridDateTimeColumn in radgrid?
Please give me with example.....


4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Oct 2008, 07:54 AM
Hello Vinod,

You can try out the following code to set the MinDate property of the GridDateTimeColumn.
cs:
 protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem dataItem = (GridEditableItem)e.Item; 
            RadDatePicker datePicker = (RadDatePicker)dataItem["date"].Controls[0]; 
            datePicker.MinDate = DateTime.Today; 
        } 
    } 

Thanks
Princy.
0
vinod
Top achievements
Rank 1
answered on 07 Oct 2008, 08:11 AM
Thanks Princy,
for Quick Replay,

i am created Grid Dynamically & adding GridDateTimeColumn 
dynamically using following code....



GridDateTimeColumn boundColumn = new GridDateTimeColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
boundColumn.DataFormatString = "{0:d}";
RadGridRow.MasterTableView.Columns.Add(boundColumn);

as per Your mail    

RadDatePicker datePicker = (RadDatePicker)dataItem["date"].Controls[0];

 i am able give mindate property.
but if  i want to applay this property to all GridDateTimeColumn in the radgrid Without specifying Column dataitems name ( "date").
means for each GridDateTimeColumn in Radgrid...





                 


0
Shinu
Top achievements
Rank 2
answered on 07 Oct 2008, 10:27 AM
Hi Vinod,

Try the following code snippet to achieve the desired scenario.

CS:
  protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (col.ColumnType == "GridDateTimeColumn") 
            { 
                GridDateTimeColumn datcol = (GridDateTimeColumn)col; 
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
                { 
                    if ((item is GridEditableItem) && (item.IsInEditMode)) 
                    { 
                        GridEditableItem edititm = (GridEditableItem)item; 
                        RadDatePicker dtpkr = (RadDatePicker)edititm[datcol.UniqueName].Controls[0]; 
                       dtpkr.MinDate = DateTime.Today; 
                    } 
                } 
            } 
        } 
    } 


Thanks
Shinu.
0
vinod
Top achievements
Rank 1
answered on 07 Oct 2008, 11:50 AM
Hello Shinu,
Thanks for Replay

basically GridDateTimeColumncolumn cannot able to displays dates before 1980/1/1. So i not able to use this for Date Of Birth for people who Born before 1980.
How to solve this issue without using template column. i am created RadGrid runtime & add GridDateTimeColumn dynamically.using following code.

  GridDateTimeColumn boundColumn = new GridDateTimeColumn();
                  boundColumn.HeaderText = strColumnName;
                  boundColumn.DataField = Item.Value;
                  boundColumn.UniqueName = strColumnName;
                  boundColumn.DataFormatString = "{0:d}";
                  boundColumn.PickerType = GridDateTimeColumnPickerType.DatePicker;                  RadGridRow.MasterTableView.Columns.Add(boundColumn);

Thanks In Advance....

Tags
Grid
Asked by
vinod
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
vinod
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or