By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Hiding column in ASP datagrid

P: n/a
Hi,

I am trying to hide a column in a datagrid I dynamicaly created, but
fail to with the following code:

....
....
foreach(XmlElement objStorageGroup in objServer.ChildNodes)
{
this.intMbSG = 0;
this.objDataGrid =
this.GetDataGrid(objStorageGroup.Attributes["Name",""].Value);
this.objDataGrid.Font.Bold = true;
this.objDataGrid.BackColor = System.Drawing.Color.Gray;
this.objDataGrid.ForeColor = System.Drawing.Color.White;
this.objDataGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
this.PlaceHolder1.Controls.Add(this.objDataGrid);
this.objDataGrid = new DataGrid();
this.objDataGrid.ItemDataBound += new
DataGridItemEventHandler(objDataGrid_ItemDataBound );
this.objDataGrid.ItemCreated += new
DataGridItemEventHandler(objDataGrid_ItemCreated);
DataTable objTable = new DataTable();
objTable.Columns.Add(new DataColumn("Store Name",typeof(string)));
objTable.Columns.Add(new DataColumn("Mailboxes",typeof(string)));
objTable.Columns.Add(new DataColumn("Quota",typeof(string)));
foreach(XmlElement objStore in objStorageGroup.ChildNodes)
{
DataRow objRow = objTable.NewRow();
objRow[0] = objStore.Attributes["Name",""].Value;
objRow[1] = objStore.ChildNodes[0].Attributes["Count",""].Value;
objRow[2] = objStore.ChildNodes[1].Attributes["Count",""].Value;
objTable.Rows.Add(objRow);
this.intMbSG = this.intMbSG +
Convert.ToInt32(objStore.ChildNodes[0].Attributes["Count",""].Value);
}
this.objDataGrid.DataSource = new DataView(objTable);
this.objDataGrid.DataBind();
this.objDataGrid.Columns[2].Visible = false;
this.objDataGrid.Width = 500;
this.objDataGrid.Font.Name = "Verdana";
this.objDataGrid.Font.Size = 10;
this.objDataGrid.HeaderStyle.Font.Bold = true;
this.objDataGrid.BackColor = System.Drawing.Color.DarkOrange;
this.objDataGrid.ItemStyle.BackColor = System.Drawing.Color.White;
this.objDataGrid.AlternatingItemStyle.BackColor =
System.Drawing.Color.White;
this.PlaceHolder1.Controls.Add(this.objDataGrid);
this.objDataGrid = this.GetDataGrid("Mailboxes in Storage
Group",this.intMbSG);
this.PlaceHolder1.Controls.Add(this.objDataGrid);
this.intMbServer = this.intMbServer + this.intMbSG;
}
....

It crashes on : this.objDataGrid.Columns[2].Visible = false; >> Index
out of range.

What am I doing wrong???

Thanks in advance!!!

Mark

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.