Blank Web Page

S

student

Hello all, could someone explain why I'm getting a blank web page when I run
start my code in a web browser? Here is the code:
Imports System.Data.SqlClient
Imports System.Data
Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

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
'Create the data connection.
Dim sqlconnectContactMgmt As New SqlConnection _
("server=(local);database=Contacts;Trusted_Connection=yes")
'Create a data adapter.
Dim sqladaptContactMgmt As New _
SqlDataAdapter("select * from Contacts", sqlconnectContactMgmt)
'Create a data set.
Dim dsContacts As New DataSet()
'Fill in the data set.
sqladaptContactMgmt.Fill(dsContacts, "Contacts")
'Display the table in a data grid using data binding.
Dim DataGrid1 As New DataGrid()
DataGrid1.DataSource = dsContacts.Tables("Contacts").DefaultView
DataGrid1.DataBind()

End Sub


End Class
 
S

Scott Allen

This line of code:

Dim DataGrid1 As New DataGrid()

is creating a new DataGrid which it goes on to bind the data to. Unfortunately,
if you just create a grid in this fashion it is not attached to the web form.
A web form has to 'know' about a DataGrid in order to display the grid, and
just creating a grid like this doesn't let the page know about the grid.

Are you using Visual Studio.NET? If so, you'll want to drag and drop a DataGrid
control onto the web form. Visual Studio will put a grid into the form and
give you a variable in the code behind to match. All you'll need to do then
is set the DataSource property and call DataBind (like you have below).

Making sense?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top