Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. I can't get my codebehind to work

I can't get my codebehind to work

Scheduled Pinned Locked Moved ASP.NET
csharpdesigndebugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bigtone78
    wrote on last edited by
    #1

    I can't get my codebehind to work. Here is the code behind code: namespace nestedRepeaters { using System.Data; using System.Data.Odbc; public class nestedRepeater : System.Web.UI.Page { public System.Web.UI.WebControls.Repeater parentRepeater; static void Main() { } public void Page_Load(object sender, System.EventArgs e) { //Create the connection and DataAdapter for the Authors table. string sConnString = "Dsn=mysqldb;Uid=bigtone78 ; Pwd="; OdbcConnection cnn = new OdbcConnection(sConnString); OdbcDataAdapter cmd1 = new OdbcDataAdapter("select * from questions",cnn); //Create and fill the DataSet. DataSet ds = new DataSet(); cmd1.Fill(ds,"questions"); //Insert code in step 4 of the next section here. //Bind the Authors table to the parent Repeater control, and call DataBind. parentRepeater.DataSource = ds.Tables["questions"]; Page.DataBind(); //Close the connection. cnn.Close(); } } } and here is where I call it in the aspx file: <%@ Page language="c#" Codebehind="test1.aspx.cs" Debug="true" AutoEventWireup="false" Inherits="nestedRepeaters.nestedRepeater" %> nothing shows up all I get is a blank screen. I think it has something to do with my main method. I don't think i should have one but the code doesnt compile if if dont use one.

    J 1 Reply Last reply
    0
    • B bigtone78

      I can't get my codebehind to work. Here is the code behind code: namespace nestedRepeaters { using System.Data; using System.Data.Odbc; public class nestedRepeater : System.Web.UI.Page { public System.Web.UI.WebControls.Repeater parentRepeater; static void Main() { } public void Page_Load(object sender, System.EventArgs e) { //Create the connection and DataAdapter for the Authors table. string sConnString = "Dsn=mysqldb;Uid=bigtone78 ; Pwd="; OdbcConnection cnn = new OdbcConnection(sConnString); OdbcDataAdapter cmd1 = new OdbcDataAdapter("select * from questions",cnn); //Create and fill the DataSet. DataSet ds = new DataSet(); cmd1.Fill(ds,"questions"); //Insert code in step 4 of the next section here. //Bind the Authors table to the parent Repeater control, and call DataBind. parentRepeater.DataSource = ds.Tables["questions"]; Page.DataBind(); //Close the connection. cnn.Close(); } } } and here is where I call it in the aspx file: <%@ Page language="c#" Codebehind="test1.aspx.cs" Debug="true" AutoEventWireup="false" Inherits="nestedRepeaters.nestedRepeater" %> nothing shows up all I get is a blank screen. I think it has something to do with my main method. I don't think i should have one but the code doesnt compile if if dont use one.

      J Offline
      J Offline
      Javier Lozano
      wrote on last edited by
      #2

      You are correct, you don't need a Main() method. This is only used for executables (console programs, windows forms). Quick Points: * Instead of calling Page.DataBind() call the DataBind() method of your repeater (parentRepeater.DataBind()). * Do your code inside an IsPostBack check so you don't end up calling the same code over and over. What do you mean that but the code doesnt compile if if dont use one? An ASP.NET page does not use the Main() method. (It doesn't even have one!) ~javier lozano (blog)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups