Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 17th, 2006, 07:41 PM
Registered User
Join Date: Oct 2006
Location: Athens, Attica, Greece.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default missing directive with simple datagrid

I have created a web form and added a datagrid by copy-paste this:
<asp:datagrid id="myDataGrid" runat="server"/>

On the Page_Load I have this code:

string strConnection;
strConnection = ConfigurationSettings.AppSettings["ConnectionString"];

SqlConnection conn = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand("SELECT TOP 15 * FROM LBS_Device", conn);


myDataGrid.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

when I try to build this, I get an error on this line:
myDataGrid.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

If I understand correctly the datagrid is not declared correct?
It needs a directive so it can use .DataSource property?
I've tried adding before Page_Load this:
protected System.Web.UI.HtmlControls.HtmlGenericControl myDataGrid;

but while this indeed adds some properties to the grid, the DataSource is not there.

Any ideas?

Thank you so much for your time,

  #2 (permalink)  
Old October 17th, 2006, 07:48 PM
Registered User
Join Date: Oct 2006
Location: Athens, Attica, Greece.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Ok, it may see stupid,
but after a last test it worked!

I have added this line just before page_load:
protected System.Web.UI.WebControls.DataGrid myDataGrid;

shouldn't this line be filled automatically by visual studio?

Similar Threads
Thread Thread Starter Forum Replies Last Post
missing a using directive or an assembly reference zhshqzyc ASP.NET 2.0 Basics 3 January 13th, 2008 03:50 AM
Missing parameters in Datagrid .net 2 kangarolf ASP.NET 2.0 Basics 1 May 17th, 2007 03:33 AM
Missing report field! - probably something simple LenexaKS Crystal Reports 0 October 10th, 2006 10:12 AM
A Simple Datagrid Question? boxwalah C# 1 February 15th, 2006 07:44 PM
Problem with DataGrid [simple one] ramana123 ASP.NET 1.0 and 1.1 Basics 3 July 8th, 2005 08:42 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.