I can't get my codebehind to work
-
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.
-
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.
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)