1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Repeater reference is lost in code behind??

Discussion in 'C#' started by fluid, Jul 22, 2006.

  1. #1
    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.
    SEMrush
    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?
     
    fluid, Jul 22, 2006 IP
    SEMrush
  2. benjymouse

    benjymouse Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In 1.x you need to put a declaration of the repeater into the codebehind, like
    Repeater myRepeater
    in the codebehind class
     
    benjymouse, Jul 23, 2006 IP
  3. fluid

    fluid Active Member

    Messages:
    679
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    70
    #3
    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?)
     
    fluid, Jul 23, 2006 IP
  4. fluid

    fluid Active Member

    Messages:
    679
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    70
    #4
    The right syntax would be:

    protected Repeater myRepeater;

    and i was missing a namespace - using System.Web.UI.WebControls;

    Thx for the help anyway.
     
    fluid, Jul 24, 2006 IP