/// <summary> /// Creates the insert row and adds it to the inner table. /// </summary> protected virtual void CreateInsertRow() { GridViewRow row = this.CreateRow(this.Rows.Count, -1, DataControlRowType.DataRow, DataControlRowState.Insert); DataControlField[] fields = new DataControlField[this.Columns.Count]; this.Columns.CopyTo(fields, 0); row.ApplyStyle(this.insertRowStyle); this.InitializeRow(row, fields); //Creates header row for empty data. if (this.Rows.Count == 0) { this.Controls.Add(new Table()); GridViewRow header = this.CreateRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal); this.InitializeRow(header, fields); //this.CreateChildTable(); this.InnerTable.Rows.Add(header); } int index = this.InnerTable.Rows.Count - (this.ShowFooter ? 1 : 0); this.InnerTable.Rows.AddAt(index, row); }
protected override void Render(HtmlTextWriter writer) { //render header row writer.Write("<table border='0' cellspacing='" + this.CellSpacing.ToString() + "' cellpadding='" + this.CellPadding.ToString() + "' style='width:" + CalculateWidth() + "'>"); GridViewRow customHeader = this.HeaderRow; if (this.HeaderRow != null) { customHeader.ApplyStyle(this.HeaderStyle); if (AutoGenerateColumns == false) { int i = 0; foreach (DataControlField col in this.Columns) { customHeader.Cells[i].ApplyStyle(col.HeaderStyle); i++; } } customHeader.RenderControl(writer); this.HeaderRow.Visible = false; } writer.Write("</table>"); //render data rows writer.Write("<div id='" + ClientID + "_div' style='" + "padding-bottom:5px;overflow-x:hidden;overflow-y:scroll;" + "width:" + CalculateWidth() + ";" + "height:" + CalculateHeight() + ";" + "background-color:#FFFFFF;'>"); //get the pager row and make invisible GridViewRow customPager = this.BottomPagerRow; if (this.BottomPagerRow != null) { this.BottomPagerRow.Visible = false; } base.Render(writer); writer.Write("</div>"); //render pager row if (customPager != null && this.PageCount > 0) { writer.Write("<table border='0' cellspacing='" + this.CellSpacing.ToString() + "' cellpadding='" + this.CellPadding.ToString() + "' style='width:" + CalculateWidth() + "'>"); customPager.ApplyStyle(this.PagerStyle); customPager.Visible = true; customPager.RenderControl(writer); writer.Write("</table>"); } }
/// <summary> /// Create header row /// </summary> private void CreateHeaderRow() { if (ShowHeaderAllways) { Table maintable = null; if (this.Controls.Count == 0) { maintable = new Table(); maintable.ApplyStyle(this.ControlStyle); this.Controls.Add(maintable); } else { maintable = this.Controls[0] as Table; } bool IsCreateHeader = false; bool IsCreateEmptyRow = false; if (maintable.Rows.Count == 0) { IsCreateHeader = true; IsCreateEmptyRow = true; } else { GridViewRow gvr = maintable.Rows[0] as GridViewRow; if (gvr.RowType == DataControlRowType.EmptyDataRow) { maintable.Rows.Clear(); IsCreateHeader = true; IsCreateEmptyRow = true; } else { IsCreateHeader = false; IsCreateEmptyRow = false; } } int ColumnCount = 0; if (IsCreateHeader) { GridViewRow gvr = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); gvr.ApplyStyle(this.HeaderStyle); for (int i = 0; i < this.Columns.Count; i++) { DataControlField column = this.Columns[i]; if (column.ShowHeader) { ColumnCount++; DataControlFieldHeaderCell tc = new DataControlFieldHeaderCell(column); tc.ApplyStyle(column.HeaderStyle); column.InitializeCell(tc, DataControlCellType.Header, DataControlRowState.Normal, 0); gvr.Cells.Add(tc); } } maintable.Rows.AddAt(0, gvr); } if (IsCreateEmptyRow) { if (this.EmptyDataText != string.Empty) { GridViewRow gvr = new GridViewRow(0, 0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); gvr.ApplyStyle(this.EmptyDataRowStyle); TableCell tc = new TableCell(); tc.Text = this.EmptyDataText; tc.ColumnSpan = ColumnCount; gvr.Cells.Add(tc); maintable.Rows.Add(gvr); } } } }