title: RadGrid OnRowDataBound equivalent
body: <p>I'm creating a gridview dynamically and using a gridview, the following code is working: </p>
  
  <pre><code>protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              for (var i = 1; i &lt;= 7; i++)
              {
                  var hDate = new HiddenField { ID = "hDate" + i, Value = string.Format("{0:yyyy-MM-dd}", _weekStart.AddDays(i - 1)) };
                  e.Row.Cells[i].Controls.Add(hDate);
                  var hEmployeeId = new HiddenField { ID = "hEmployeeId" + i, Value = ((DataRowView)e.Row.DataItem).Row["EmployeeId"].ToString() };
                  e.Row.Cells[i].Controls.Add(hEmployeeId);
  
                  var lstStart = TimeListBox("lstStart" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "S"].ToString());
                  e.Row.Cells[i].Controls.Add(lstStart);
                  var lstEnd = TimeListBox("lstEnd" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "E"].ToString());
                  e.Row.Cells[i].Controls.Add(lstEnd);
                  var lstStoreSection = StoreSectionListBox("lstStoreSection" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "SS"].ToString());
                  e.Row.Cells[i].Controls.Add(lstStoreSection);
              }
  
              var lnkView = new LinkButton { ID = "lnkView", Text = "View" };
              lnkView.Click += ViewDetails;
              lnkView.CommandArgument = ((DataRowView)e.Row.DataItem).Row["Id"].ToString();
              e.Row.Cells[8].Controls.Add(lnkView);
          }
      }
  </code></pre>
  
  <p>I'm trying to accomplish the same using the RadGrid control form telerik. Unfortunately the OnRowDataBound method doesn't exist. Any ideas? Thank you</p>
  
  <p>Here is the full code. Basically it does create a gridview representing the 7 days of the week, in each cell I have 3 ListBox: one for Time start, one for time end and the other one for the section where the employee will work. Everything works fine some small glithes. But I want it to work with RadGrid.</p>
  
  <pre><code>public partial class Sample2 : System.Web.UI.Page
  {
      private DateTime _weekStart, _weekEnd;
  
      private readonly string _strConnString =
          ConfigurationManager.ConnectionStrings["EmpireIntranetConnectionString"].ConnectionString;
      public SqlConnection Con = new SqlConnection();
  
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              GetStartAndEndDate();
              GenerateGridViewStructure();
          }
          BindGrid();
      }
  
      private void GenerateGridViewStructure()
      {
          var bfield = new BoundField { HeaderText = "Employé", DataField = "Employee" };
          gvSchedule.Columns.Add(bfield);
  
          var tfield = new TemplateField { HeaderText = "Lundi " + string.Format("{0:dd}", _weekStart) };
          gvSchedule.Columns.Add(tfield);
          tfield = new TemplateField { HeaderText = "Mardi " + string.Format("{0:dd}", _weekStart.AddDays(1)) };
          gvSchedule.Columns.Add(tfield);
          tfield = new TemplateField { HeaderText = "Mercredi " + string.Format("{0:dd}", _weekStart.AddDays(2)) };
          gvSchedule.Columns.Add(tfield);
          tfield = new TemplateField { HeaderText = "Jeudi " + string.Format("{0:dd}", _weekStart.AddDays(3)) };
          gvSchedule.Columns.Add(tfield);
          tfield = new TemplateField { HeaderText = "Vendredi " + string.Format("{0:dd}", _weekStart.AddDays(4)) };
          gvSchedule.Columns.Add(tfield);
          tfield = new TemplateField { HeaderText = "Samedi " + string.Format("{0:dd}", _weekStart.AddDays(5)) };
          gvSchedule.Columns.Add(tfield);
          tfield = new TemplateField { HeaderText = "Dimanche " + string.Format("{0:dd}", _weekStart.AddDays(6)) };
          gvSchedule.Columns.Add(tfield);
  
          tfield = new TemplateField { HeaderText = "View" };
          gvSchedule.Columns.Add(tfield);
      }
  
      private void BindGrid()
      {
          var dt = new DataTable();
          dt.Columns.AddRange(new[]
          {
              new DataColumn("Id", typeof (int)),
              new DataColumn("EmployeeId", typeof (int)),
              new DataColumn("Employee", typeof (string)),
              new DataColumn("MondayS", typeof (string)), 
              new DataColumn("MondayE", typeof (string)), 
              new DataColumn("MondaySS", typeof (string)),
              new DataColumn("TuesdayS", typeof (string)),
              new DataColumn("TuesdayE", typeof (string)),
              new DataColumn("TuesdaySS", typeof (string)),
              new DataColumn("WednesdayS", typeof (string)),
              new DataColumn("WednesdayE", typeof (string)),
              new DataColumn("WednesdaySS", typeof (string)),
              new DataColumn("ThursdayS",typeof(string)),
              new DataColumn("ThursdayE",typeof(string)),
              new DataColumn("ThursdaySS",typeof(string)),
              new DataColumn("FridayS",typeof(string)),
              new DataColumn("FridayE",typeof(string)),
              new DataColumn("FridaySS",typeof(string)),
              new DataColumn("SaturdayS",typeof(string)),
              new DataColumn("SaturdayE",typeof(string)),
              new DataColumn("SaturdaySS",typeof(string)),
              new DataColumn("SundayS",typeof(string)),
              new DataColumn("SundayE",typeof(string)),
              new DataColumn("SundaySS",typeof(string))
          });
  
  
          Con.ConnectionString = _strConnString;
          Con.Open();
  
          var cmd = new SqlCommand
          {
              Connection = Con,
              CommandText = "sp_GetWeeklySchedule '" + string.Format("{0:yyyy-MM-dd}", _weekStart) + "'"
          };
  
          using (var dataReader = cmd.ExecuteReader())
          {
              var i = 0;
              while (dataReader.Read())
              {
                  i++;
                  dt.Rows.Add(i, dataReader["id"], dataReader["Name"].ToString(),
                      GetSubstringFromReader(dataReader["Monday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Monday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Monday"].ToString(), 2),
                      GetSubstringFromReader(dataReader["Tuesday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Tuesday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Tuesday"].ToString(), 2),
                      GetSubstringFromReader(dataReader["Wednesday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Wednesday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Wednesday"].ToString(), 2),
                      GetSubstringFromReader(dataReader["Thursday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Thursday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Thursday"].ToString(), 2),
                      GetSubstringFromReader(dataReader["Friday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Friday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Friday"].ToString(), 2),
                      GetSubstringFromReader(dataReader["Saturday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Saturday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Saturday"].ToString(), 2),
                      GetSubstringFromReader(dataReader["Sunday"].ToString(), 0),
                      GetSubstringFromReader(dataReader["Sunday"].ToString(), 1),
                      GetSubstringFromReader(dataReader["Sunday"].ToString(), 2));
              }
          }
          Con.Close();
          gvSchedule.DataSource = dt;
          gvSchedule.DataBind();
      }
  
      private static string GetSubstringFromReader(string str, int i)
      {
          if (str == "")
          {
              return "";
          }
          return str.Split('-')[i];
      }
  
      protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              for (var i = 1; i &lt;= 7; i++)
              {
                  var hDate = new HiddenField { ID = "hDate" + i, Value = string.Format("{0:yyyy-MM-dd}", _weekStart.AddDays(i - 1)) };
                  e.Row.Cells[i].Controls.Add(hDate);
                  var hEmployeeId = new HiddenField { ID = "hEmployeeId" + i, Value = ((DataRowView)e.Row.DataItem).Row["EmployeeId"].ToString() };
                  e.Row.Cells[i].Controls.Add(hEmployeeId);
  
                  var lstStart = TimeListBox("De", "lstStart" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "S"].ToString());
                  e.Row.Cells[i].Controls.Add(lstStart);
                  var lstEnd = TimeListBox("À", "lstEnd" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "E"].ToString());
                  e.Row.Cells[i].Controls.Add(lstEnd);
                  var lstStoreSection = StoreSectionListBox("lstStoreSection" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "SS"].ToString());
                  e.Row.Cells[i].Controls.Add(lstStoreSection);
              }
  
              var lnkView = new LinkButton { ID = "lnkView", Text = "View" };
              lnkView.Click += ViewDetails;
              lnkView.CommandArgument = ((DataRowView)e.Row.DataItem).Row["Id"].ToString();
              e.Row.Cells[8].Controls.Add(lnkView);
          }
      }
  
      private static string GetDay(int i)
      {
          var day = "";
          switch (i)
          {
              case 1:
                  day = "Monday";
                  break;
              case 2:
                  day = "Tuesday";
                  break;
              case 3:
                  day = "Wednesday";
                  break;
              case 4:
                  day = "Thursday";
                  break;
              case 5:
                  day = "Friday";
                  break;
              case 6:
                  day = "Saturday";
                  break;
              case 7:
                  day = "Sunday";
                  break;
          }
          return day;
      }
  
      protected void ViewDetails(object sender, EventArgs e)
      {
          var lnkView = (LinkButton)sender;
          var row = (GridViewRow)lnkView.NamingContainer;
          var id = lnkView.CommandArgument;
          var name = row.Cells[0].Text;
          var start = ((ListBox)row.FindControl("lstStart1")).SelectedValue;
          var end = ((ListBox)row.FindControl("lstEnd1")).SelectedValue;
          ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Id: " + id + " Name: " + name + " Start: " + start + " End: " + end + "')", true);
      }
  
      private void GetStartAndEndDate()
      {
          var d = DateTime.Today;
          var offset = d.DayOfWeek - DayOfWeek.Monday;
  
          _weekStart = d.AddDays(-offset);
          _weekEnd = _weekStart.AddDays(6);
      }
  
      protected void btnNext_Click(object sender, EventArgs e)
      {
          _weekStart = _weekEnd.AddDays(1);
          GenerateGridViewStructure();
          BindGrid();
      }
  
      private ListBox StoreSectionListBox(string name, string value)
      {
          var lst = new ListBox { ID = name, Rows = 1 };
          lst.Items.Add(new ListItem("Section", ""));
  
          Con.ConnectionString = _strConnString;
          Con.Open();
  
          var cmd = new SqlCommand
          {
              Connection = Con,
              CommandText = "SELECT * FROM StoreSections"
          };
  
          using (var dataReader = cmd.ExecuteReader())
          {
              while (dataReader.Read())
              {
                  var item = new ListItem
                  {
                      Value = dataReader["id"].ToString(),
                      Text = dataReader["Description"].ToString()
                  };
                  lst.Items.Add(item);
              }
          }
          Con.Close();
          if (value != null)
              lst.SelectedValue = value;
          return lst;
      }
  
      private static ListBox TimeListBox(string label, string name, string value)
      {
          var lst = new ListBox { ID = name, Rows = 1 };
          lst.Items.Add(new ListItem(label, ""));
          var start = new DateTime(1900, 1, 1, 9, 0, 0);
          var end = new DateTime(1900, 1, 1, 22, 0, 0);
          var current = start;
          while (current &lt;= end)
          {
              lst.Items.Add(new ListItem(current.ToString("HH:mm"), current.ToString("HH:mm")));
              current = current.AddMinutes(15);
          }
          if (value != null)
              lst.SelectedValue = value;
          return lst;
      }
  
      protected void btnSave_Click(object sender, EventArgs e)
      {
          var totalRows = gvSchedule.Rows.Count;
  
          for (var r = 0; r &lt; totalRows; r++)
          {
              var row = gvSchedule.Rows[r];
  
              for (int c = 1; c &lt;= 7; c++)
              {
                  var employeeId = (HiddenField)row.FindControl("hEmployeeId" + c);
                  var vEmployeeId = employeeId.Value;
  
                  var date = (HiddenField)row.FindControl("hDate" + c);
                  var vDate = date.Value;
  
                  var start = (ListBox)row.FindControl("lstStart" + c);
                  var vStart = start.SelectedValue;
  
                  var end = (ListBox)row.FindControl("lstEnd" + c);
                  var vEnd = end.SelectedValue;
  
                  if (vStart != "" &amp;&amp; vEnd != "")
                  {
                      var con = new SqlConnection(_strConnString);
                      con.Open();
                      var sql = "sp_UpdateEmployeeSchedule '" + vEmployeeId + "','" + vDate + "','" + vStart + "','" +
                                vEnd + "'";
                      var cmd = new SqlCommand(sql, con);
                      cmd.ExecuteNonQuery();
                      con.Close();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Feel free to give hitn to improve my code. Thank you</p>