How to Set Controls Width or Height Programmatically

Waqas Anwar
22 December 2010

If you want to set ASP.NET controls width or height properties programmatically then you can use built in Unit class as shown below:

GridView1.Width = new Unit(70, UnitType.Percentage);
GridView1.Width = new Unit(500, UnitType.Pixel);

GridView1.Height = new Unit(70, UnitType.Percentage);
GridView1.Height = new Unit(500, UnitType.Pixel);