Newbie: Datagrid Comes Up 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
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>
 
K

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.
 
S

Sambathraj

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

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.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top