all groups > asp.net datagrid control > april 2005 >
You're in the

asp.net datagrid control

group:

Newbie: Datagrid Comes Up Blank?!?


Newbie: Datagrid Comes Up Blank?!? Altemir
4/30/2005 12:27:20 PM
asp.net datagrid control:
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>
Re: Newbie: Datagrid Comes Up Blank?!? Ken Cox [Microsoft MVP]
5/1/2005 12:00:00 AM
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.

[quoted text, click to view]

Re: Newbie: Datagrid Comes Up Blank?!? Sambathraj
5/2/2005 12:00:00 AM
Hi,
Replace the code MyDataGrid = New DataGrid() with
Page.FindControl("MyDataGrid"). Then it will work fine.
Regards,
Sambath

[quoted text, click to view]

Re: Newbie: Datagrid Comes Up Blank?!? Scott M.
5/2/2005 12:00:00 AM
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.


[quoted text, click to view]

AddThis Social Bookmark Button