Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Newbie: Datagrid Comes Up Blank?!?

Reply
Thread Tools

Newbie: Datagrid Comes Up Blank?!?

 
 
Altemir
Guest
Posts: n/a
 
      04-30-2005
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>

<ASPataGrid 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>

 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      05-02-2005
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: oups.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>
>
> <ASPataGrid 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>
>



 
Reply With Quote
 
 
 
 
Sambathraj
Guest
Posts: n/a
 
      05-02-2005
Hi,
Replace the code MyDataGrid = New DataGrid() with
Page.FindControl("MyDataGrid"). Then it will work fine.
Regards,
Sambath

"Altemir" <> wrote in message
news: oups.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>
>
> <ASPataGrid 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>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      05-02-2005
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: oups.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>
>>
>> <ASPataGrid 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>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where does datagrid's uniqueID comes from? John Dalberg ASP .Net 0 12-20-2005 08:05 AM
Internet connection comes and goes... =?Utf-8?B?Q2Fyb2xlIFVL?= Wireless Networking 1 07-20-2005 01:11 PM
How to Update dataset from datagrid,when data comes from text file? Marisha ASP .Net 1 07-17-2005 07:37 AM
Complete newbie when it comes to wireless! =?Utf-8?B?VGVsbW9yZQ==?= Wireless Networking 2 05-17-2005 03:41 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57