Alter GridView columns properties

Posted on 2006-05-15
Last Modified: 2010-07-27
VS 2005


New to ASP.NET (and especially VS 2005). I'm struggling with the formatting of a GridView control's columns.

In General Decs:
      Dim AttAdapter As SqlDataAdapter
      Dim AttSet As dataset
          Dim Connection As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("AttConString"))
          Dim AttCommand As SqlCommand

In New():

      AttCommand = New SqlCommand("dbo.MySproc", Connection)
        AttCommand.CommandType = Data.CommandType.StoredProcedure

        AttAdapter = New SqlDataAdapter(AttCommand)
        AttSet = New DataSet
        AttAdapter.Fill(AttSet, "AttDets")

In load():

        Me.MyGridView.DataSource = AttSet
        Me.MyGridView.DataMember = "AttDets"


The GridView control is populated correctly however I cannot set the GridView column widths. If I try:


in a button click handler it returns 0.

The columns are known at design time so I can specify this then if required. Please could someone let me know what I am missing?


EDIT - changed title and some text - I had written DataView instead of GridView a couple of times.
Question by:pootle_flump
    LVL 11

    Author Comment

    Duh - forgot to mention that for unimportant reasons I can't use the GridView headers - I am having to create my own. As such, I hide the headers but would like to format the column widths rather than have them autofit to the data.
    LVL 11

    Author Comment

    Hi Mods

    I think I have cracked this. I will post the solution shortly.

    LVL 11

    Author Comment


    Mods - apols for the link. If you would rather I pasted the solution on here please let me know.

    Please may I also have my points refunded?


    Accepted Solution

    Closed, 500 points refunded.
    The Experts Exchange
    Community Support Moderator of all Ages

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now