Newbie: Datagrid Comes Up Blank?!?

Discussion in 'ASP .Net Datagrid Control' started by Altemir, Apr 30, 2005.

  1. Altemir

    Altemir Guest

    Just trying to connect an ASP.NET page to an SQL database. When I run
    the page, I get no errors but no recordset results are returned via the
    datagrid control -- it is completely blank.

    The only thing displayed is the "Job Dispatch List" page title which
    executed as plain HTML.

    Code is as follows. Any ideas?
    --------------

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>

    <HTML>

    <SCRIPT language="VB" runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)

    Dim MyDataset As DataSet
    Dim MyConnection As SqlConnection
    Dim MyDataAdapter As SqlDataAdapter
    Dim myDataGrid as DataGrid

    MyConnection = New SqlConnection("Data Source=apollo;Initial
    Catalog=ProductionStatus;uid=sa;pwd=mypassword" )
    MyDataAdapter = New SqlDataAdapter("SELECT ID FROM dbo_PART",
    MyConnection)

    MyDataset = New DataSet()
    MyDataAdapter.Fill(MyDataset,"Parts")

    MyDataGrid = New DataGrid()
    MyDataGrid.DataSource=MyDataset.Tables("Parts")
    MyDataGrid.DataBind()

    End Sub

    </SCRIPT>

    <TITLE>Job Dispatch List</TITLE>
    <BODY>

    <H3><font face="Arial">Job Dispatch List</font></H3>

    <ASP:DataGrid id="MyDataGrid" runat="server"
    Width="700"
    BackColor="#ccccff"
    BorderColor="black"
    ShowFooter="true"
    CellPadding=3
    CellSpacing="0"
    Font-Name="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#aaaadd"
    EnableViewState="false"
    />


    </BODY>
    </HTML>
    Altemir, Apr 30, 2005
    #1
    1. Advertising

  2. Have you confirmed that you are getting data from the query?

    Is the Load event firing? You'd want autoeventwireup set to true for that.

    "Altemir" <> wrote in message
    news:...
    > Just trying to connect an ASP.NET page to an SQL database. When I run
    > the page, I get no errors but no recordset results are returned via the
    > datagrid control -- it is completely blank.
    >
    > The only thing displayed is the "Job Dispatch List" page title which
    > executed as plain HTML.
    >
    > Code is as follows. Any ideas?
    > --------------
    >
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.SqlClient" %>
    >
    > <HTML>
    >
    > <SCRIPT language="VB" runat="server">
    >
    > Sub Page_Load(Sender As Object, E As EventArgs)
    >
    > Dim MyDataset As DataSet
    > Dim MyConnection As SqlConnection
    > Dim MyDataAdapter As SqlDataAdapter
    > Dim myDataGrid as DataGrid
    >
    > MyConnection = New SqlConnection("Data Source=apollo;Initial
    > Catalog=ProductionStatus;uid=sa;pwd=mypassword" )
    > MyDataAdapter = New SqlDataAdapter("SELECT ID FROM dbo_PART",
    > MyConnection)
    >
    > MyDataset = New DataSet()
    > MyDataAdapter.Fill(MyDataset,"Parts")
    >
    > MyDataGrid = New DataGrid()
    > MyDataGrid.DataSource=MyDataset.Tables("Parts")
    > MyDataGrid.DataBind()
    >
    > End Sub
    >
    > </SCRIPT>
    >
    > <TITLE>Job Dispatch List</TITLE>
    > <BODY>
    >
    > <H3><font face="Arial">Job Dispatch List</font></H3>
    >
    > <ASP:DataGrid id="MyDataGrid" runat="server"
    > Width="700"
    > BackColor="#ccccff"
    > BorderColor="black"
    > ShowFooter="true"
    > CellPadding=3
    > CellSpacing="0"
    > Font-Name="Verdana"
    > Font-Size="8pt"
    > HeaderStyle-BackColor="#aaaadd"
    > EnableViewState="false"
    > />
    >
    >
    > </BODY>
    > </HTML>
    >
    Ken Cox [Microsoft MVP], May 2, 2005
    #2
    1. Advertising

  3. Altemir

    Sambathraj Guest

    Hi,
    Replace the code MyDataGrid = New DataGrid() with
    Page.FindControl("MyDataGrid"). Then it will work fine.
    Regards,
    Sambath

    "Altemir" <> wrote in message
    news:...
    > Just trying to connect an ASP.NET page to an SQL database. When I run
    > the page, I get no errors but no recordset results are returned via the
    > datagrid control -- it is completely blank.
    >
    > The only thing displayed is the "Job Dispatch List" page title which
    > executed as plain HTML.
    >
    > Code is as follows. Any ideas?
    > --------------
    >
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.SqlClient" %>
    >
    > <HTML>
    >
    > <SCRIPT language="VB" runat="server">
    >
    > Sub Page_Load(Sender As Object, E As EventArgs)
    >
    > Dim MyDataset As DataSet
    > Dim MyConnection As SqlConnection
    > Dim MyDataAdapter As SqlDataAdapter
    > Dim myDataGrid as DataGrid
    >
    > MyConnection = New SqlConnection("Data Source=apollo;Initial
    > Catalog=ProductionStatus;uid=sa;pwd=mypassword" )
    > MyDataAdapter = New SqlDataAdapter("SELECT ID FROM dbo_PART",
    > MyConnection)
    >
    > MyDataset = New DataSet()
    > MyDataAdapter.Fill(MyDataset,"Parts")
    >
    > MyDataGrid = New DataGrid()
    > MyDataGrid.DataSource=MyDataset.Tables("Parts")
    > MyDataGrid.DataBind()
    >
    > End Sub
    >
    > </SCRIPT>
    >
    > <TITLE>Job Dispatch List</TITLE>
    > <BODY>
    >
    > <H3><font face="Arial">Job Dispatch List</font></H3>
    >
    > <ASP:DataGrid id="MyDataGrid" runat="server"
    > Width="700"
    > BackColor="#ccccff"
    > BorderColor="black"
    > ShowFooter="true"
    > CellPadding=3
    > CellSpacing="0"
    > Font-Name="Verdana"
    > Font-Size="8pt"
    > HeaderStyle-BackColor="#aaaadd"
    > EnableViewState="false"
    > />
    >
    >
    > </BODY>
    > </HTML>
    >
    Sambathraj, May 2, 2005
    #3
  4. Altemir

    Scott M. Guest

    FindControl is a DataGrid method used to locate child controls within a cell
    of the grid. It is not a Page method used to find controls on the page.

    Even if it were, there is nothing wrong with referring to a control on a web
    page (not a child control of something else) by its name as in MyDataGrid =
    New DataGrid(). The problem, in fact is that the MyDataGrid variable is
    being set to a new DataGrid and therefore breaking its pointer to the
    correctly set up one.


    "Sambathraj" <> wrote in message
    news:...
    > Hi,
    > Replace the code MyDataGrid = New DataGrid() with
    > Page.FindControl("MyDataGrid"). Then it will work fine.
    > Regards,
    > Sambath
    >
    > "Altemir" <> wrote in message
    > news:...
    >> Just trying to connect an ASP.NET page to an SQL database. When I run
    >> the page, I get no errors but no recordset results are returned via the
    >> datagrid control -- it is completely blank.
    >>
    >> The only thing displayed is the "Job Dispatch List" page title which
    >> executed as plain HTML.
    >>
    >> Code is as follows. Any ideas?
    >> --------------
    >>
    >> <%@ Import Namespace="System.Data" %>
    >> <%@ Import Namespace="System.Data.SqlClient" %>
    >>
    >> <HTML>
    >>
    >> <SCRIPT language="VB" runat="server">
    >>
    >> Sub Page_Load(Sender As Object, E As EventArgs)
    >>
    >> Dim MyDataset As DataSet
    >> Dim MyConnection As SqlConnection
    >> Dim MyDataAdapter As SqlDataAdapter
    >> Dim myDataGrid as DataGrid
    >>
    >> MyConnection = New SqlConnection("Data Source=apollo;Initial
    >> Catalog=ProductionStatus;uid=sa;pwd=mypassword" )
    >> MyDataAdapter = New SqlDataAdapter("SELECT ID FROM dbo_PART",
    >> MyConnection)
    >>
    >> MyDataset = New DataSet()
    >> MyDataAdapter.Fill(MyDataset,"Parts")
    >>
    >> MyDataGrid = New DataGrid()
    >> MyDataGrid.DataSource=MyDataset.Tables("Parts")
    >> MyDataGrid.DataBind()
    >>
    >> End Sub
    >>
    >> </SCRIPT>
    >>
    >> <TITLE>Job Dispatch List</TITLE>
    >> <BODY>
    >>
    >> <H3><font face="Arial">Job Dispatch List</font></H3>
    >>
    >> <ASP:DataGrid id="MyDataGrid" runat="server"
    >> Width="700"
    >> BackColor="#ccccff"
    >> BorderColor="black"
    >> ShowFooter="true"
    >> CellPadding=3
    >> CellSpacing="0"
    >> Font-Name="Verdana"
    >> Font-Size="8pt"
    >> HeaderStyle-BackColor="#aaaadd"
    >> EnableViewState="false"
    >> />
    >>
    >>
    >> </BODY>
    >> </HTML>
    >>

    >
    >
    Scott M., May 2, 2005
    #4
    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. Marisha
    Replies:
    1
    Views:
    2,513
    =?Utf-8?B?Sm9zZXBoIE0uIFdhaGJh?=
    Jul 17, 2005
  2. John Dalberg

    Where does datagrid's uniqueID comes from?

    John Dalberg, Dec 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    408
    John Dalberg
    Dec 20, 2005
  3. cn99

    newbie comes.

    cn99, Apr 2, 2004, in forum: Python
    Replies:
    0
    Views:
    311
  4. Page comes up blank

    , Nov 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    336
  5. Replies:
    9
    Views:
    362
    CBFalconer
    Mar 29, 2007
Loading...

Share This Page