Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • Administrators
Posted

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.

   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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...