columns -
GridView Grid = new GridView();
HyperLinkField hyfield = new HyperLinkField();
hfield.HeaderText = "Forums";
hfield.HeaderStyle.BackColor = System.Drawing.Color.LightBlue;
hfield.DataNavigateUrlFields = new string[] { "Fid" };
hfield.DataNavigateUrlFormatString = "ViewForum.aspx?Forum={0}";
hfield.DataTextField = "ForumName";
hfield.ItemStyle.Width = 400; //column width
Grid.Columns.Add(hyfield);
BoundField bfield1 = new BoundField();
bfield1.HeaderText = "Topics";
bfield1.HeaderStyle.BackColor = System.Drawing.Color.LightBlue;
bfield1.DataField = "TopicsCount";
Grid.Columns.Add(bfield1);
BoundField bfield2 = new BoundField();
bfield2.HeaderText = "Posts";
bfield2.HeaderStyle.BackColor = System.Drawing.Color.LightBlue;
bfield2.DataField = "PostsCount";
Grid.Columns.Add(bfield2);
Grid.AutoGenerateColumns = false;
Grid.BackColor = System.Drawing.Color.LightBlue;
Grid.DataSource = Data;
Grid.DataBind();
sometimes it's needed to add the dynamic GridView control
to any placeholder control like panel to display.
panel1.Controls.Add(Grid);