How to Set Controls Width or Height Programmatically

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);



About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies