Why does my GridView no display?

here's some code.  The Gridview2 does not display. Can please anyone tell me what is missing from this code?

        GridView1.AutoGenerateColumns = False

        Dim dt As New DataTable

        Dim col0 As New DataColumn
        Dim col1 As New DataColumn
        Dim col2 As New DataColumn
        Dim col3 As New DataColumn
        Dim col4 As New DataColumn

        Dim row0 As DataRow
        Dim row1 As DataRow


        col0.ColumnName = "Cost Center Name"
        col0.DataType = System.Type.GetType("System.String")
        dt.Columns.Add(col0)

        col1.ColumnName = "Total Budget"
        col1.DataType = System.Type.GetType("System.String")
        dt.Columns.Add(col1)

        col2.ColumnName = "Used Budget"
        col2.DataType = System.Type.GetType("System.String")
        dt.Columns.Add(col2)

        col3.ColumnName = "Remaining Budget"
        col3.DataType = System.Type.GetType("System.String")
        dt.Columns.Add(col3)

        col4.ColumnName = "Cost Center ID"
        col4.DataType = System.Type.GetType("System.Int32")
        dt.Columns.Add(col4)


        row0 = dt.NewRow()
        row0(0) = "asasas"
        dt.Rows.Add(row0)

        row1 = dt.NewRow()
        row1(1) = "44444"

        dt.Rows.Add(row1)

        GridView2.AutoGenerateColumns = False
        GridView2.Caption = "66666666"
        GridView2.DataSource = dt
        GridView2.Visible = True
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Change following code


        GridView2.AutoGenerateColumns = False
        GridView2.Caption = "66666666"
        GridView2.DataSource = dt
        GridView2.Visible = True

to


        GridView2.AutoGenerateColumns = True
        GridView2.Caption = "66666666"
        GridView2.DataSource = dt
        GridView2.DateBind()
0
 
CodeCruiserCommented:
Is it in ASP.NET? Try adding a GridView2.DataBind()
0
 
Ady FootSharePoint ConsultantCommented:
This gridview control you're using - is it a third party control?

Regards,

Ady
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Ady FootSharePoint ConsultantCommented:
Ah if it's ASP.net you can disregard my post above.  
0
 
HLRosenbergerAuthor Commented:
No.  the one that comes with Visual Studio.  I'm also using another instance of it in Bound mode, and that works fine.  
0
 
HLRosenbergerAuthor Commented:
I'm coding in VB.  I'm am creating an ASP.NET WEB page.
0
 
CodeCruiserCommented:
You mean its a WinForms app? What version of VS?


  GridView2.AutoGenerateColumns = False

Set it to true? Or do you have columns defind in designer?
0
 
CodeCruiserCommented:
Did you add

GridView2.DataBind()

at the end?
0
 
HLRosenbergerAuthor Commented:
I want to totally design it in code.  It show 3 column in the Studio, but I think they are there just for the IDE, because the grid designer window does hot show any columns.
0
 
HLRosenbergerAuthor Commented:
This line did the trick.

GridView2.AutoGenerateColumns = True

I thought AutoGenerateColumns was only used to Auto Generate columns created in the designer.

Thanks!
0
 
HLRosenbergerAuthor Commented:
Thanks!
0
 
CodeCruiserCommented:
Glad its sorted :-)
Autogenerate means that generate the grid columns automatically for the columns in the datatable.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.