Displaying a DataGrid

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
I have been programming (to various degree's of success) with VB.NET for quite a while, but i am a complete noobie when it comes to ASP.NET.

Initially i created a screen where i can copy the contents of a textbox to a label upon a button click. This was incredibly simple and worked straight away. Now i've tried to move on to using datagrids. I am unable to make the datagrid display, i drag it onto the layout form, press Run and the rest of the form displays perfect, but for some reason the datagrid is just completely invisible as if it wasnt even there.

Can someone please tell me what i am doing wrong please?
 
Are you using the DataGrid with a valid data source? If not then you probably should. If you are then you need to remember to call DataBind on the control to get itself to render.

e.g.
Visual Basic:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim conn As New SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=true")
        Dim cmd As New SqlCommand("SELECT * FROM Products", conn)

        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds)
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()
    End Sub
 
Thanks PD.

I was missing the DataBind(), I never use it with VB.NET and i swear it works just fine. Only started with ASP today, so there is a few things i need to get use too.
 
Back
Top