Put that code after your databind(). ......................... Stephen Russell - Senior Visual Studio Developer, DBA
Memphis, TN 901.246-0159 > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of eddiec > Sent: Thursday, April 02, 2009 9:41 PM > To: DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web > Services,.NET Remoting > Subject: [DotNetDevelopment] hide gridview column at runtime > > > Hi, > > I am trying to hide a column of a gridview > > Code in C# is > myDataGrid.Columns[0].Visible = false; > > When I run the code I receive an error: > Exception Details: System.ArgumentOutOfRangeException: Index was out > of range. Must be non-negative and less than the size of the > collection. > Parameter name: index > > I guess the probem is that where I am accessing the grid it hasn't > been rendered yet. > > I have tried putting the code after data binding in the page load > event and also in the RowDataBound event handler but receive the same > error either way. > > Help! > > cheers > > eddiec :-) > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.0.238 / Virus Database: 270.11.38/2037 - Release Date: > 04/02/09 06:09:00
