Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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

Hi,
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);

conn.Open();

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

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,
Panos

  #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
Default

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?

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.