I have been tearing my hair out for the last few days trying to get this example to work
Code:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="EventDrivenGrid.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:DataGrid
id="dgCustomers"
runat="server"
Font-Size="8pt"
Width="466px" Height="278px"
HeaderStyle-BackColor="Yellow"
BorderWidth="5"
BorderColor="000099"
AlternatingItemStyle-BackColor="LightGrey"
AutoGenerateColumns="False"
<Columns>
<asp:BoundColumn HeaderText="Company Name" DataField="CompanyName" />
<asp:BoundColumn HeaderText="Contact" DataField="ContactName" />
<asp:BoundColumn HeaderText="Title" DataField="ContactTitle" />
<asp:BoundColumn HeaderText="Phone" DataField="Phone" />
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
with some c# behind
Code:
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 EventDrivenGrid
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object Source, System.EventArgs E)
{
if(!IsPostBack)
{
// Create Connection String
string strConnection =
"server=****; uid=sa; pwd=*********; database=northwind";
//Create the command String
string strCommand = "Select * from Customers";
//Create the data set command object and dataset
SqlDataAdapter dataAdapter =
new SqlDataAdapter(strCommand, strConnection);
DataSet dataSet = new DataSet();
//Fill the data set
dataAdapter.Fill(dataSet,"Products");
SqlCommandBuilder bldr = new SqlCommandBuilder(dataAdapter);
//Get the table
DataTable datatable = dataSet.Tables[0];
dgCustomers.dataSource = dataTable;
dgCustomers.dataBind();
}
}
HOWEVER i keep getting the error
"The server tag is not well formed" refering to line 13
Code:
<asp:DataGrid
id="dgCustomers"
runat="server"
Meaning the c# cant fing the dgCustomers!
Can anyone help, i need to move on with this!!!
Thanks for any help offered