Blank Web Page

Discussion in 'ASP .Net' started by student, Jan 3, 2005.

  1. student

    student Guest

    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
    student, Jan 3, 2005
    #1
    1. Advertising

  2. student

    Scott Allen Guest

    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?

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    > 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
    >
    Scott Allen, Jan 3, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David
    Replies:
    10
    Views:
    891
    David
    Jul 27, 2005
  2. ibiza
    Replies:
    0
    Views:
    738
    ibiza
    Jan 16, 2006
  3. David R
    Replies:
    2
    Views:
    3,848
    David R
    Mar 23, 2006
  4. Gunjal
    Replies:
    0
    Views:
    464
    Gunjal
    Jul 19, 2007
  5. JL
    Replies:
    7
    Views:
    261
    Bob Barrows [MVP]
    Jan 30, 2007
Loading...

Share This Page