Datagrid not visible

  • Thread starter Thread starter Fabrizio
  • Start date Start date
F

Fabrizio

Hi,
I created an aspx page with a Datagrid control that
should list a bunch of records from a MS Access database
table.
When I load the page on Web Server , the datagrid itself
is not visible. The dataset is filled corretly, but the
datagrid won't show.
Thanks,
Fabrizio
 
Have you put in Page_Load datagrid.DataBind() ?
Without calling the DataBind() method of a bindable web control, the web
control will not display the bound data.

Hope this helps
Dan Cimpoiesu
 
Hi Fabrizio,

I have writen a small sample to bind the dataset to datagrid. I use the
SqlServer's default database table "jobs" as datasource.
You can check to see which steps you missed.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace datagridbind
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
DataSet ds=new DataSet();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=");
adapter.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

If you have anything unclear, please feel free to tell me.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Fabrizio" <[email protected]>
| Sender: "Fabrizio" <[email protected]>
| Subject: Datagrid not visible
| Date: Thu, 13 Nov 2003 23:18:20 -0800
| Lines: 10
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOqf3t+kbp9J5XhTUyey90yYvzjpQ==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:199256
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi,
| I created an aspx page with a Datagrid control that
| should list a bunch of records from a MS Access database
| table.
| When I load the page on Web Server , the datagrid itself
| is not visible. The dataset is filled corretly, but the
| datagrid won't show.
| Thanks,
| Fabrizio
|
|
 
Back
Top