Insert rows in a GridView

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow) {
  Data.DataRowView eRowDataItem = e.Row.DataItem;
  Data.DataRow eRowDataItemRow = eRowDataItem.Row;
  string Comments = "";
  if (!object.ReferenceEquals(eRowDataItemRow.Item("Comments"), DBNull.Value)) {
   Comments = eRowDataItemRow.Item("Comments");
  }
  if (!string.IsNullOrEmpty(Comments)) {
   Table eRowParentTable = e.Row.Parent;
   GridViewRow NewGridViewRow = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
   TableCell NewTableCell = new TableCell();
   NewTableCell.ColumnSpan = 6;
   NewTableCell.Width = Unit.Percentage(100);
   NewTableCell.Text = Comments;
   NewGridViewRow.Cells.Add(NewTableCell);
   HtmlGenericControl NewSpan = new HtmlGenericControl("span");
   NewSpan.InnerText = Comments;
   NewTableCell.Controls.Add(NewSpan);
   eRowParentTable.Rows.AddAt(eRowParentTable.Rows.Count, NewGridViewRow);
  }
 }
}

No comments:

Post a Comment