user3036965
user3036965

Reputation: 155

ASP.NET Basic GridView control not displaying at all

I am getting started with a basic asp.net gridview control and I just dont seem to be able to make it visible in the web browser at all in an asp.net web application.

Here is what I have just to get myself started off. In the aspx page ...

<asp:GridView ID="myGr" runat="server" BackColor="Aqua" AutoGenerateColumns="True" Width="100%"  ViewStateMode="Enabled"></asp:GridView>

In the code behind I have ...

Dim tbl As New DataTable
        tbl.Columns.Add("ID", GetType(Int32))
        tbl.Columns.Add("Name", GetType(String))
        tbl.Columns.Add("Birthday", GetType(Date))
        Dim pers As DataRow = tbl.NewRow
        pers("ID") = 1
        pers("Name") = "Tim"
        pers("Birthday") = New Date(1973, 6, 9)


        myGr.DataSource = tbl
    myGr.DataBind()

Would be great if anyone could give me some basic advice on this control

Upvotes: 0

Views: 225

Answers (2)

PrzemG
PrzemG

Reputation: 795

You create row but you do not add it to the table.

You have to add line like that:

tbl.Rows.Add(pers)

Upvotes: 0

Thanos Markou
Thanos Markou

Reputation: 2623

You need to add the row you inserted to the datatable tbl. Because you haven't done this, the datatable is empty so the Gridview is empty too.

Like that: tbl.Rows.add(pers)

Upvotes: 1

Related Questions