System.Web.UI.WebControls.GridView.DataBind C# (CSharp) Method

DataBind() public final method

public final DataBind ( ) : void
return void
		public sealed override void DataBind ()
		{
			DataKeyArrayList.Clear ();
			cachedKeyProperties = null;
			base.DataBind ();

			keys = new DataKeyArray (DataKeyArrayList);
			
			GridViewRow row = HeaderRow;
			if (row != null)
				row.Visible = ShowHeader;

			row = FooterRow;
			if (row != null)
				row.Visible = ShowFooter;
		}
		

Usage Example

Example #1
0
        public static void ShowGridAlways(ref GridView gridView, ref DataTable dt, string emptyMessage)
        {
            if (dt.Rows.Count == 0)
            {
                // Remove contraints so an empty row can be added.
                dt.Constraints.Clear();
                foreach (DataColumn dc in dt.Columns)
                    dc.AllowDBNull = true;

                // Add a blank row to the dataset
                dt.Columns[0].AllowDBNull = true;
                dt.Rows.Add(dt.NewRow());
                // Bind the DataSet to the GridView
                gridView.DataSource = dt;
                gridView.DataBind();
                // Get the number of columns to know what the Column Span should be
                int columnCount = gridView.Rows[0].Cells.Count;
                // Call the clear method to clear out any controls that you use in the columns.  I use a dropdown list in one of the column so this was necessary.
                gridView.Rows[0].Cells.Clear();
                gridView.Rows[0].Cells.Add(new TableCell());
                gridView.Rows[0].Cells[0].ColumnSpan = columnCount;
                gridView.Rows[0].Cells[0].Text = emptyMessage;
            }
            else
            {
                gridView.DataSource = dt;
                gridView.DataBind();
            }
        }
All Usage Examples Of System.Web.UI.WebControls.GridView::DataBind