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
|