Newbie: Datagrid is Completely Blank?!?

A

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 is
executed as plain HTML.

Code is as follows. Any ideas as to what could be going wrong?
--------------


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClie­nt" %>

<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=s­a;pwd=mypassword" )
MyDataAdapter = New SqlDataAdapter("SELECT ID FROM dbo_PART",
MyConnection)

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

MyDataGrid = New DataGrid()
MyDataGrid.DataSource=MyDatase­t.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>
 
N

Norman Yuan

Try to remove

MyDataGrid = New DataGrid()

from the seerver side script code: You already have the DataGrid created in
the HTML part and the variable "MyDataGrid" is originally pointed to the
DataGrid. Once you point the variable to a new DataGrid in your code, you
get a NEW data grid, which IS NOT the one you created in design stage (in
HTML part). The data will be bound to the DataGrid you just created in code.
Since the DataGrid you created in ocde is not added to the Page's control
collection, it will not show in the page, it only stays in server's memory
during the page loading and then be discarded. So, you page should be blank.

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 is
executed as plain HTML.

Code is as follows. Any ideas as to what could be going wrong?
--------------


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClie­nt" %>

<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=s­a;pwd=mypassword" )
MyDataAdapter = New SqlDataAdapter("SELECT ID FROM dbo_PART",
MyConnection)

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

MyDataGrid = New DataGrid()
MyDataGrid.DataSource=MyDatase­t.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>
 
G

Guest

Hi Altemir,

Sincem you don't explicitly declared columns for the datagrid, you need to
set
AutoGenerateColumns = ture. Otherwise there is no column to show data.

HTH

Elton Wang
(e-mail address removed)
 

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

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top