Home All Groups Group Topic Archive Search About
Author
30 Apr 2005 7:27 PM
Altemir
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>

Author
2 May 2005 2:53 AM
Ken Cox [Microsoft MVP]
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.

Show quoteHide quote
"Altemir" <altemir***@yahoo.com> wrote in message
news:1114889240.853992.249180@z14g2000cwz.googlegroups.com...
> 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>
>
Author
2 May 2005 1:42 PM
Sambathraj
Hi,
Replace the code MyDataGrid = New DataGrid() with
Page.FindControl("MyDataGrid"). Then it will work fine.
Regards,
Sambath

Show quoteHide quote
"Altemir" <altemir***@yahoo.com> wrote in message
news:1114889240.853992.249180@z14g2000cwz.googlegroups.com...
> 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>
>
Author
2 May 2005 2:29 PM
Scott M.
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.


Show quoteHide quote
"Sambathraj" <v_sambath_***@hotmail.com> wrote in message
news:ONO3iwxTFHA.3636@TK2MSFTNGP14.phx.gbl...
> Hi,
> Replace the code MyDataGrid = New DataGrid() with
> Page.FindControl("MyDataGrid"). Then it will work fine.
> Regards,
> Sambath
>
> "Altemir" <altemir***@yahoo.com> wrote in message
> news:1114889240.853992.249180@z14g2000cwz.googlegroups.com...
>> 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>
>>
>
>