|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie: Datagrid Comes Up Blank?!?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> 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> > 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> > 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> >> > >
I've lost my drop down list box!
Columns are displayed twice binding ArrayLists to DataGrids-- how to name the columns? DataRowView - deleting rows: A little quiz -or- Why doesn't this work... Show Date only from DateTime in DataGrid trying to display header only Wrong window gets the content ItemStyle question MXDatagrid paging problem Datagrid Moving up and down |
|||||||||||||||||||||||