I've just started moving my application logic to code behind files. Now i had a page which was working fine with the inline <script ... > logic, but since i moved it into a code behind file, it doesnt work. test.aspx <%@ Page Language="C#" AutoEventWireup="True" EnableSessionState="False" EnableViewState="False" Src="codebehind/FirstCodeBehind.aspx.cs" Inherits="FirstCodeBehind" %> FirstCodeBehind.aspx.cs using System; using System.Web.UI; using System.Data; using System.Data.Odbc; using System.Configuration; public class FirstCodeBehind : Page { private void Page_Load(object sender, System.EventArgs e) { ' .... sql statement, open connection, execute sql command OdbcDataReader myReader; myReader = cmd.ExecuteReader(); myRepeater.DataSource = myReader; myRepeater.DataBind(); myReader.Close(); con.Close(); } } On compilation, it says The name 'myRepeater' does not exist in the current context What could be the problem?
In 1.x you need to put a declaration of the repeater into the codebehind, like Repeater myRepeater in the codebehind class
If i add: Repeater myRepeater; just before myRepeater.DataSource = myReader; i get this error message: CS0246: The type or namespace name 'Repeater' could not be found (are you missing a using directive or an assembly reference?)
The right syntax would be: protected Repeater myRepeater; and i was missing a namespace - using System.Web.UI.WebControls; Thx for the help anyway.