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

GridDateTimeColumncolumn cannot able to displays dates before 1980/1/1.

4 Answers 55 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, 01:05 PM
Hello All,


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....

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Oct 2008, 07:18 AM
Hello vinod,

You can set this in ItemCreated event. Here is an example:

if(e.Item is GridDataItem)
{
    ((e.Item as GridDataItem)["YourColumnUniqueName"].Controls[0] as RadDatePicker).MinDate = ...
}

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
vinod
Top achievements
Rank 1
answered on 08 Oct 2008, 07:50 AM
Thanks for replay.

But it is not working for Below code. i am created radgrid Dynamically.


    protected void Page_Load(object sender, EventArgs e)
    {
              DefineGrid();   
        }

protected void DefineGrid()
  {
      try
      {
        
          RadGridRow.Controls.Clear();
          RadGridRow.Columns.Clear();
          int _intEntityID =  Int32.Parse(RadRowsEntity.SelectedValue.ToString());
          RadGridRow.Width = Unit.Percentage(100);
          RadGridRow.GridLines = GridLines.None;
          RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
          RadGridRow.NeedDataSource += new GridNeedDataSourceEventHandler(RadGridRow_NeedDataSource);
          RadGridRow.InsertCommand += new GridCommandEventHandler(RadGridRow_InsertCommand);
          RadGridRow.UpdateCommand += new GridCommandEventHandler(RadGridRow_UpdateCommand);
          RadGridRow.CancelCommand += new GridCommandEventHandler(RadGridRow_CancelCommand);
          RadGridRow.DeleteCommand += new GridCommandEventHandler(RadGridRow_DeleteCommand);
          RadGridRow.ItemCreated += new GridItemEventHandler(RadGridRow_ItemCreated);
          RadGridRow.ItemDataBound += new GridItemEventHandler(RadGridRow_ItemDataBound);
          RadGridRow.Width = Unit.Percentage(100);
          RadGridRow.AllowPaging = true;
          RadGridRow.AutoGenerateColumns = false;
          RadGridRow.MasterTableView.AutoGenerateColumns = false;
          RadGridRow.ClientSettings.AllowDragToGroup = true;
          RadGridRow.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
          RadGridRow.ShowStatusBar = true;

          DataTable dt = new DataTable();

          String strWorksitePositionManagerEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
          DataSet dsWorksitePositionManagerEntityname = new DataSet();
          dsWorksitePositionManagerEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strWorksitePositionManagerEntityname);
          strWorksitePositionManagerEntityname = dsWorksitePositionManagerEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
          dsWorksitePositionManagerEntityname.Dispose();
          SqlCommand _sqlCommand;
          //This is Only For WorksitePositionManager Start
          if (strWorksitePositionManagerEntityname == "WorksitePositionManager")
          {
              string _strSqlWorksitePositionManager = " select WorksitePositionManager.WorksitePositionManagerID as [WorksitePositionManagerID~0],";
             _strSqlWorksitePositionManager += "  WorksitePositionManager.RowName as [RowName~0],";
             _strSqlWorksitePositionManager += " WorksitePositionManager.StartDate as [StartDate~0], ";
             _strSqlWorksitePositionManager += " WorksitePositionManager.EndDate as [EndDate~0],";
             _strSqlWorksitePositionManager += " WorksitePosition.Rowname as [RowName~76],";
             _strSqlWorksitePositionManager += " (select Rowname from WorksitePosition ";
             _strSqlWorksitePositionManager += " where WorksitePositionID= WorksitePositionManager.ManagerWspID) ";
             _strSqlWorksitePositionManager += " as [ManagerWorkSitePosition~76~1]  from   WorksitePositionManager inner join WorksitePosition ";
             _strSqlWorksitePositionManager += " on WorksitePositionManager.WorksitePositionID = WorksitePosition.WorksitePositionID ";
              _sqlCommand = new SqlCommand(_strSqlWorksitePositionManager, _sqlConnection);
          }
          //This is Only For WorksitePositionManager End
          else
          {

           _sqlCommand = new SqlCommand("BuildDynamicRowsQuerry", _sqlConnection);

           _sqlCommand.CommandType = CommandType.StoredProcedure;
           _sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = _intEntityID;
          }
          _sqlConnection.Open();
          _sqlCommand.ExecuteNonQuery();
          SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
          _sqlAdapter.Fill(dt);
          _sqlConnection.Close();
          string StrSqlTablePk = "SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (select EntityName from Entity where EntityID='" + _intEntityID + "'))";
          DataSet dsPktable = new DataSet();
          dsPktable = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlTablePk);
          string strTablePKName = string.Empty;
          strTablePKName = dsPktable.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
          dsPktable.Clear();
          dsPktable.Dispose();
          RadGridRow.MasterTableView.DataKeyNames = new string[] { strTablePKName + "~0" };//as Column Name In stored procedure

          for (int i = 0; i < dt.Columns.Count; i++)
          {


              ListItem Item = new ListItem(dt.Columns[i].ToString(), dt.Columns[i].ToString());

              string[] arr = dt.Columns[i].ToString().Split('~'); // split the string's spaces
              string strColumnName = arr[0].ToString();
              string strChkColumnType = arr[1].ToString();
              String strGridColumnName = Item.Text; ;
              string StrEntityName = string.Empty;
              string strPKName = string.Empty;
              string strColName = string.Empty;

              if (strChkColumnType != "0")//FOR FKEntityID CHECK
              {
                
                      String strSqlEntityname = "select EntityName from Entity where EntityID='" + strChkColumnType + "'";
                      DataSet dsEntityname = new DataSet();
                      dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
                      StrEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
                      dsEntityname.Dispose();

                      string StrSqlColNameTEMP = "(SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (Select EntityName From Entity Where EntityID = '" + strChkColumnType + "')) ) C WHERE cid = 2)    ";
                      DataSet dsColName = new DataSet();
                      dsColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlColNameTEMP);
                      strGridColumnName = dsColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
                      dsColName.Clear();
                      dsColName.Dispose();

                      DataSet dsPk = new DataSet();
                      DataSet dstColName = new DataSet();
                      string strSqlPk = " SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ";
                      string strSqlColName = " SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ) C WHERE cid = 2 ";
                      dsPk = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlPk);
                      strPKName = dsPk.Tables[0].Rows[0]["NAME"].ToString();
                      dsPk.Clear();
                      dsPk.Dispose();

                      dstColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlColName);
                      strColName = dstColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim(); ;
                      dstColName.Clear();
                      dstColName.Dispose();
                  

              }

              if ((dt.Columns[i].DataType.ToString() == "System.String") || (dt.Columns[i].DataType.ToString() == "System.Int32"))
              {
                  if (strChkColumnType != "0")//FOR FKEntityID CHECK
                  {
                      if (dt.Columns[i].ToString() != "ManagerWorkSitePosition~76~1")//This is for WorksitePositionManager
                      {

                          string templateColumnName = StrEntityName;
                          GridTemplateColumn templateColumn = new GridTemplateColumn();

                          templateColumn.ItemTemplate = new MyItemTemplate(StrEntityName + "MyItemTemplate" + i.ToString(), Item.Value.ToString());
                         templateColumn.EditItemTemplate = new MyEditTemplate(StrEntityName + "MyEditTemplate" + i.ToString(), StrEntityName, strPKName, strColName, Item.Value.ToString(), strColumnName);
                          RadGridRow.MasterTableView.Columns.Add(templateColumn);
                          templateColumn.HeaderText = templateColumnName;
                          templateColumn.UniqueName = strColumnName;
                      }
                      else
                      {
                          string templateColumnName = "ManagerWorkSitePositon";
                          GridTemplateColumn templateColumn = new GridTemplateColumn();

                          templateColumn.ItemTemplate = new MyItemTemplateManager(Item.Value.ToString());
                          templateColumn.EditItemTemplate = new MyEditTemplateManager(Item.Value.ToString());
                          RadGridRow.MasterTableView.Columns.Add(templateColumn);
                          templateColumn.HeaderText = templateColumnName;
                          templateColumn.UniqueName = strColumnName;
                      }
                  }
                  else
                  {
                      if (strColumnName != "FullName")
                      {
                          GridBoundColumn boundColumn = new GridBoundColumn();
                          boundColumn.HeaderText = strColumnName;
                          boundColumn.DataField = Item.Value;

                          boundColumn.UniqueName = strColumnName;
                          if (strTablePKName == strColumnName)
                          {

                              boundColumn.ReadOnly = true;//To Hide Pk ID In Edit Form

                          }

                          RadGridRow.MasterTableView.Columns.Add(boundColumn);
                      }

                  }

              }
              else if (dt.Columns[i].DataType.ToString() == "System.Boolean")
              {
                  GridCheckBoxColumn boundColumn = new GridCheckBoxColumn();
                  boundColumn.HeaderText = strColumnName;
                  boundColumn.DataField = Item.Value;
                  boundColumn.UniqueName = strColumnName;
                  RadGridRow.MasterTableView.Columns.Add(boundColumn);

              }
              else if (dt.Columns[i].DataType.ToString() == "System.DateTime")
              {
                  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);
                  

              }
          }
          RadGridRow.DataSource = dt;
          dt.Dispose();
          GridEditCommandColumn col = new GridEditCommandColumn();
          RadGridRow.MasterTableView.Columns.Add(col);
          col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
          col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
          col.CancelText = "Cancel";
          col.EditText = "Edit";
          col.UpdateText = "Update";
          col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;

          GridButtonColumn BtnDelete = new GridButtonColumn();

          RadGridRow.MasterTableView.Columns.Add(BtnDelete);

          BtnDelete.Text = "Delete";

          BtnDelete.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
          BtnDelete.ItemStyle.VerticalAlign = VerticalAlign.Middle;
          BtnDelete.CommandName = "Delete";
          BtnDelete.ConfirmDialogType = GridConfirmDialogType.RadWindow;
          BtnDelete.ConfirmText = "Are You Sure to Delete This Record?";
          BtnDelete.ConfirmTitle = "Delete";



          RadGridRow.MasterTableView.Columns.FindByUniqueName(strTablePKName).Visible = false;

          RadGridRow.ClientSettings.Scrolling.AllowScroll = true;
          RadGridRow.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(380);
          RadGridRow.MasterTableView.EditMode = GridEditMode.EditForms;

          RadGridRow.MasterTableView.EditFormSettings.EditColumn.InsertImageUrl = "../Admin/Update.gif";
          RadGridRow.MasterTableView.EditFormSettings.EditColumn.UpdateImageUrl = "../Admin/Update.gif";
          RadGridRow.AllowPaging = true;
          RadGridRow.AllowSorting = true;
          RadGridRow.PagerStyle.FirstPageImageUrl = "PagingFirst.gif";
          RadGridRow.PagerStyle.LastPageImageUrl = "PagingLast.gif";
          RadGridRow.PagerStyle.NextPageImageUrl = "PagingNext.gif";
          RadGridRow.PagerStyle.PrevPageImageUrl = "PagingPrev.gif";
          RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
          RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
          RadGridRow.PageSize = pageCount;
          RadGridRow.MasterTableView.PageSize = pageCount;
          RadGridRow.MasterTableView.CommandItemSettings.RefreshText = "";
          RadGridRow.MasterTableView.CommandItemSettings.AddNewRecordText = "Add New";
          RadGridRow.Rebind();
      }
      catch (Exception ex)
      {

          LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
          RadGridRow.Controls.Add(new LiteralControl("Error  . Reason: " + ex.Message));

      }

  }


  protected void RadGridRow_ItemCreated(object sender, GridItemEventArgs e)
    {
      if(e.Item is GridDataItem)
{
    ((e.Item as GridDataItem)["Startdate"].Controls[0] as RadDatePicker).MinDate = ...
}
    }

0
vinod
Top achievements
Rank 1
answered on 08 Oct 2008, 09:22 AM
But it is not working for Below code. i am created radgrid Dynamically.


    protected void Page_Load(object sender, EventArgs e)
    {
              DefineGrid();   
        }

protected void DefineGrid()
  {
      try
      {
        
          RadGridRow.Controls.Clear();
          RadGridRow.Columns.Clear();
          int _intEntityID =  Int32.Parse(RadRowsEntity.SelectedValue.ToString());
          RadGridRow.Width = Unit.Percentage(100);
          RadGridRow.GridLines = GridLines.None;
          RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
          RadGridRow.NeedDataSource += new GridNeedDataSourceEventHandler(RadGridRow_NeedDataSource);
          RadGridRow.InsertCommand += new GridCommandEventHandler(RadGridRow_InsertCommand);
          RadGridRow.UpdateCommand += new GridCommandEventHandler(RadGridRow_UpdateCommand);
          RadGridRow.CancelCommand += new GridCommandEventHandler(RadGridRow_CancelCommand);
          RadGridRow.DeleteCommand += new GridCommandEventHandler(RadGridRow_DeleteCommand);
          RadGridRow.ItemCreated += new GridItemEventHandler(RadGridRow_ItemCreated);
          RadGridRow.ItemDataBound += new GridItemEventHandler(RadGridRow_ItemDataBound);
          RadGridRow.Width = Unit.Percentage(100);
          RadGridRow.AllowPaging = true;
          RadGridRow.AutoGenerateColumns = false;
          RadGridRow.MasterTableView.AutoGenerateColumns = false;
          RadGridRow.ClientSettings.AllowDragToGroup = true;
          RadGridRow.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
          RadGridRow.ShowStatusBar = true;

          DataTable dt = new DataTable();

          String strWorksitePositionManagerEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
          DataSet dsWorksitePositionManagerEntityname = new DataSet();
          dsWorksitePositionManagerEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strWorksitePositionManagerEntityname);
          strWorksitePositionManagerEntityname = dsWorksitePositionManagerEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
          dsWorksitePositionManagerEntityname.Dispose();
          SqlCommand _sqlCommand;
          //This is Only For WorksitePositionManager Start
          if (strWorksitePositionManagerEntityname == "WorksitePositionManager")
          {
              string _strSqlWorksitePositionManager = " select WorksitePositionManager.WorksitePositionManagerID as [WorksitePositionManagerID~0],";
             _strSqlWorksitePositionManager += "  WorksitePositionManager.RowName as [RowName~0],";
             _strSqlWorksitePositionManager += " WorksitePositionManager.StartDate as [StartDate~0], ";
             _strSqlWorksitePositionManager += " WorksitePositionManager.EndDate as [EndDate~0],";
             _strSqlWorksitePositionManager += " WorksitePosition.Rowname as [RowName~76],";
             _strSqlWorksitePositionManager += " (select Rowname from WorksitePosition ";
             _strSqlWorksitePositionManager += " where WorksitePositionID= WorksitePositionManager.ManagerWspID) ";
             _strSqlWorksitePositionManager += " as [ManagerWorkSitePosition~76~1]  from   WorksitePositionManager inner join WorksitePosition ";
             _strSqlWorksitePositionManager += " on WorksitePositionManager.WorksitePositionID = WorksitePosition.WorksitePositionID ";
              _sqlCommand = new SqlCommand(_strSqlWorksitePositionManager, _sqlConnection);
          }
          //This is Only For WorksitePositionManager End
          else
          {

           _sqlCommand = new SqlCommand("BuildDynamicRowsQuerry", _sqlConnection);

           _sqlCommand.CommandType = CommandType.StoredProcedure;
           _sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = _intEntityID;
          }
          _sqlConnection.Open();
          _sqlCommand.ExecuteNonQuery();
          SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
          _sqlAdapter.Fill(dt);
          _sqlConnection.Close();
          string StrSqlTablePk = "SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (select EntityName from Entity where EntityID='" + _intEntityID + "'))";
          DataSet dsPktable = new DataSet();
          dsPktable = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlTablePk);
          string strTablePKName = string.Empty;
          strTablePKName = dsPktable.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
          dsPktable.Clear();
          dsPktable.Dispose();
          RadGridRow.MasterTableView.DataKeyNames = new string[] { strTablePKName + "~0" };//as Column Name In stored procedure

          for (int i = 0; i < dt.Columns.Count; i++)
          {


              ListItem Item = new ListItem(dt.Columns[i].ToString(), dt.Columns[i].ToString());

              string[] arr = dt.Columns[i].ToString().Split('~'); // split the string's spaces
              string strColumnName = arr[0].ToString();
              string strChkColumnType = arr[1].ToString();
              String strGridColumnName = Item.Text; ;
              string StrEntityName = string.Empty;
              string strPKName = string.Empty;
              string strColName = string.Empty;

              if (strChkColumnType != "0")//FOR FKEntityID CHECK
              {
                
                      String strSqlEntityname = "select EntityName from Entity where EntityID='" + strChkColumnType + "'";
                      DataSet dsEntityname = new DataSet();
                      dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
                      StrEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
                      dsEntityname.Dispose();

                      string StrSqlColNameTEMP = "(SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (Select EntityName From Entity Where EntityID = '" + strChkColumnType + "')) ) C WHERE cid = 2)    ";
                      DataSet dsColName = new DataSet();
                      dsColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlColNameTEMP);
                      strGridColumnName = dsColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
                      dsColName.Clear();
                      dsColName.Dispose();

                      DataSet dsPk = new DataSet();
                      DataSet dstColName = new DataSet();
                      string strSqlPk = " SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ";
                      string strSqlColName = " SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ) C WHERE cid = 2 ";
                      dsPk = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlPk);
                      strPKName = dsPk.Tables[0].Rows[0]["NAME"].ToString();
                      dsPk.Clear();
                      dsPk.Dispose();

                      dstColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlColName);
                      strColName = dstColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim(); ;
                      dstColName.Clear();
                      dstColName.Dispose();
                  

              }

              if ((dt.Columns[i].DataType.ToString() == "System.String") || (dt.Columns[i].DataType.ToString() == "System.Int32"))
              {
                  if (strChkColumnType != "0")//FOR FKEntityID CHECK
                  {
                      if (dt.Columns[i].ToString() != "ManagerWorkSitePosition~76~1")//This is for WorksitePositionManager
                      {

                          string templateColumnName = StrEntityName;
                          GridTemplateColumn templateColumn = new GridTemplateColumn();

                          templateColumn.ItemTemplate = new MyItemTemplate(StrEntityName + "MyItemTemplate" + i.ToString(), Item.Value.ToString());
                         templateColumn.EditItemTemplate = new MyEditTemplate(StrEntityName + "MyEditTemplate" + i.ToString(), StrEntityName, strPKName, strColName, Item.Value.ToString(), strColumnName);
                          RadGridRow.MasterTableView.Columns.Add(templateColumn);
                          templateColumn.HeaderText = templateColumnName;
                          templateColumn.UniqueName = strColumnName;
                      }
                      else
                      {
                          string templateColumnName = "ManagerWorkSitePositon";
                          GridTemplateColumn templateColumn = new GridTemplateColumn();

                          templateColumn.ItemTemplate = new MyItemTemplateManager(Item.Value.ToString());
                          templateColumn.EditItemTemplate = new MyEditTemplateManager(Item.Value.ToString());
                          RadGridRow.MasterTableView.Columns.Add(templateColumn);
                          templateColumn.HeaderText = templateColumnName;
                          templateColumn.UniqueName = strColumnName;
                      }
                  }
                  else
                  {
                      if (strColumnName != "FullName")
                      {
                          GridBoundColumn boundColumn = new GridBoundColumn();
                          boundColumn.HeaderText = strColumnName;
                          boundColumn.DataField = Item.Value;

                          boundColumn.UniqueName = strColumnName;
                          if (strTablePKName == strColumnName)
                          {

                              boundColumn.ReadOnly = true;//To Hide Pk ID In Edit Form

                          }

                          RadGridRow.MasterTableView.Columns.Add(boundColumn);
                      }

                  }

              }
              else if (dt.Columns[i].DataType.ToString() == "System.Boolean")
              {
                  GridCheckBoxColumn boundColumn = new GridCheckBoxColumn();
                  boundColumn.HeaderText = strColumnName;
                  boundColumn.DataField = Item.Value;
                  boundColumn.UniqueName = strColumnName;
                  RadGridRow.MasterTableView.Columns.Add(boundColumn);

              }
              else if (dt.Columns[i].DataType.ToString() == "System.DateTime")
              {
                  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);
                  

              }
          }
          RadGridRow.DataSource = dt;
          dt.Dispose();
          GridEditCommandColumn col = new GridEditCommandColumn();
          RadGridRow.MasterTableView.Columns.Add(col);
          col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
          col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
          col.CancelText = "Cancel";
          col.EditText = "Edit";
          col.UpdateText = "Update";
          col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;

          GridButtonColumn BtnDelete = new GridButtonColumn();

          RadGridRow.MasterTableView.Columns.Add(BtnDelete);

          BtnDelete.Text = "Delete";

          BtnDelete.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
          BtnDelete.ItemStyle.VerticalAlign = VerticalAlign.Middle;
          BtnDelete.CommandName = "Delete";
          BtnDelete.ConfirmDialogType = GridConfirmDialogType.RadWindow;
          BtnDelete.ConfirmText = "Are You Sure to Delete This Record?";
          BtnDelete.ConfirmTitle = "Delete";



          RadGridRow.MasterTableView.Columns.FindByUniqueName(strTablePKName).Visible = false;

          RadGridRow.ClientSettings.Scrolling.AllowScroll = true;
          RadGridRow.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(380);
          RadGridRow.MasterTableView.EditMode = GridEditMode.EditForms;

          RadGridRow.MasterTableView.EditFormSettings.EditColumn.InsertImageUrl = "../Admin/Update.gif";
          RadGridRow.MasterTableView.EditFormSettings.EditColumn.UpdateImageUrl = "../Admin/Update.gif";
          RadGridRow.AllowPaging = true;
          RadGridRow.AllowSorting = true;
          RadGridRow.PagerStyle.FirstPageImageUrl = "PagingFirst.gif";
          RadGridRow.PagerStyle.LastPageImageUrl = "PagingLast.gif";
          RadGridRow.PagerStyle.NextPageImageUrl = "PagingNext.gif";
          RadGridRow.PagerStyle.PrevPageImageUrl = "PagingPrev.gif";
          RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
          RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
          RadGridRow.PageSize = pageCount;
          RadGridRow.MasterTableView.PageSize = pageCount;
          RadGridRow.MasterTableView.CommandItemSettings.RefreshText = "";
          RadGridRow.MasterTableView.CommandItemSettings.AddNewRecordText = "Add New";
          RadGridRow.Rebind();
      }
      catch (Exception ex)
      {

          LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
          RadGridRow.Controls.Add(new LiteralControl("Error  . Reason: " + ex.Message));

      }

  }


  protected void RadGridRow_ItemCreated(object sender, GridItemEventArgs e)
    {
      if(e.Item is GridDataItem)
{
    ((e.Item as GridDataItem)["Startdate"].Controls[0] as RadDatePicker).MinDate = ...
}
    }
0
vinod
Top achievements
Rank 1
answered on 10 Oct 2008, 11:47 AM
Hello All I found solution for this problem ..


i am adding CreateColumnEditor event  Runtime using following code...

 RadGridRow.CreateColumnEditor += new GridCreateColumnEditorEventHandler(RadGridRow_CreateColumnEditor);

Code for Event
if (e.Column.UniqueName.ToLower().Trim() == "Date")
        {
            e.ColumnEditor = new RadDatePickerEditorClass.RadDatePickerEditor();
        }


Follwing Class used for datetime Picker Creation......


using System;
using Telerik.WebControls;


    public class RadDatePickerEditor: GridTextColumnEditor
    {
        private RadDatePicker picker;

        protected override void LoadControlsFromContainer()
        {
            this.picker = this.ContainerControl.Controls[0] as RadDatePicker;
        }

        public override bool IsInitialized
        {
            get
            {
                return this.picker != null;
            }
        }

        public override string Text
        {
            get
            {
                if (picker.DbSelectedDate == null)
                {
                    return string.Empty;
                }

                return this.picker.DbSelectedDate.ToString();
            }
            set
            {
                this.picker.DbSelectedDate = value;
            }
        }

        protected override void AddControlsToContainer()
        {
            picker = new RadDatePicker();
            picker.ID = "editPicker";
            ContainerControl.Controls.Add(picker);
            picker.MinDate = new DateTime(1900,1,1);
        }
    }





Tags
Grid
Asked by
vinod
Top achievements
Rank 1
Answers by
Vlad
Telerik team
vinod
Top achievements
Rank 1
Share this question
or