I am using an ASP.NET GridView control, created dynamically with C# on a SharePoint web part. I am having some troubles setting the properties. Specifically, the ShowHeader property seems to be completely ignored, and it is set like so:
gv.ShowHeader = false;
This seems to work fine with the System.Web.UI.WebControls.DataGrid, which I had previously used. I'm also having this issue with many of the other properties, such as BorderColor, BorderWidth, etc. However, CellPadding and CellSpacing work just fine when set similarly:
gv.CellPadding = 2;
gv.CellSpacing = 2;
I don't understand where the problem is. Here is the DataGrid code I had been using, which worked fine:
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Specs");
DataSet flipped_ds = FlipDataSet(ds);
DataView dv = flipped_ds.Tables[0].DefaultView;
DataGrid outputGrid = new DataGrid();
outputGrid.DataSource = dv;
outputGrid.DataBind();
outputGrid.ShowHeader = false;
Controls.Add(outputGrid);
Here is the code that I have replaced this with for my GridView:
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Bobst Specs");
DataSet flipped_ds = FlipDataSet(ds);
DataView dv = flipped_ds.Tables[0].DefaultView;
GridView gv = new GridView();
gv.DataSource = dv;
gv.DataBind();
gv.AutoGenerateColumns = true;
gv.CellPadding = 2;
gv.CellSpacing = 2;
gv.ShowHeader = false;
Controls.Add(gv);
Thanks for any help that I can get!