No display when previewed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tjc0ol
    New Member
    • Nov 2007
    • 26

    No display when previewed

    Hi guys,
    I'm an .NET newbie, I need help.
    Why is it that when I preview my aspx page it won't show up anything except this line:
    <p>The data will be refreshed 10 seconds from now: <%= DateTime.Now %></p>

    Here's my code below:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ OutputCache Duration="10" VaryByParam="None" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Import Namespace="System.Data" %>
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Page Data Caching</title>
    <script type="text/c#" language="C#" runat="server">
    DataView objDV;
    void Page_Load() {
    	if (IsPostBack) {
    		dgEmployees.DataSource = GetEmployees();
    		dgEmployees.DataBind();
    	}
    }
    
    DataView GetEmployees() {
    	DataSet objDS = new DataSet();	
    	OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["DNS"]);
    	OleDbDataAdapter objDA;
    	
    	objDV = (DataView)Cache["Employees"];
    	if (objDV == null) {
    		objDA = new OleDbDataAdapter("SELECT * FROM Employees", objConn);
    		objDA.Fill(objDS, "Employees");
    		objDV = objDS.Tables["Employees"].DefaultView;
    		Cache["Employees"] = objDV;
    	}
    	
    	return objDV;
    }
    void dgEmployees_Sort(Object s, DataGridSortCommandEventArgs e) {
    	objDV = GetEmployees();
    	objDV.Sort = e.SortExpression;
    	dgEmployees.DataSource = objDV;
    	dgEmployees.DataBind();
    }
    </script>
    </head>
    <body>
    <form runat="server">
    <asp:DataGrid ID="dgEmployees" runat="server" AutoGenerateColumns="false" GridLines="None" AllowSorting="true" OnSortCommand="dgEmployees_Sort">
    	<ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="#000000" />
    	<HeaderStyle Font-Names="Arial" Font-Size="10pt" ForeColor="#FFFFFF" Font-Bold="true" BackColor="#003366" />
    	<AlternatingItemStyle Font-Names="Arial" Font-Size="10pt" BackColor="#CCCCCC" />
    	<Columns>
    		<asp:BoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" />
    		<asp:BoundColumn DataField="Extension" HeaderText="Extension" SortExpression="Extension" />
    	</Columns>
    	</asp:DataGrid>
    <p>The data will be refreshed 10 seconds from now: <%= DateTime.Now %></p>
    </form>
    </body>
    </html>
    thanks. -tj
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What version of asp.NET are you using? This looks like you are using VS2003 maybe?

    And are you sure that this page is
    A)Saved as an aspx page
    and
    B)Correctly deployed to the IIS server?

    Comment

    • tjc0ol
      New Member
      • Nov 2007
      • 26

      #3
      Originally posted by Plater
      What version of asp.NET are you using? This looks like you are using VS2003 maybe?

      And are you sure that this page is
      A)Saved as an aspx page
      and
      B)Correctly deployed to the IIS server?
      Honestly I don't know how to check my asp.NET version, all I know is that I'm using Expression web on my aspx pages. My other aspx example pages runs smoothly but this example above doesn't.

      Yes it was saved as an aspx page.

      I think its in .NET Framework 1.1(version 1.1.4322.573) since I can't find any IIS server here. I can't find it in Administrative tools.

      Here's my previous aspx example below that runs correctly:
      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <%@ OutputCache Duration="10" VaryByParam="None" %>
      <%@ Import Namespace="System.Data.OleDb" %>
      <%@ Import Namespace="System.Data" %>
      <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Cached DataGrid</title>
      <script type="text/c#" language="C#" runat="server">
      OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["DNS"]);
      OleDbDataAdapter objDA;
      DataSet objDS = new DataSet();
      void Page_Load() {
      	objDA = new OleDbDataAdapter("SELECT * FROM Employees", objConn);
      	objDA.Fill(objDS, "Employees");
      	dgEmployees.DataSource = objDS;
      	dgEmployees.DataBind();
      }
      </script>
      </head>
      <body>
      <form runat="server">
      	<asp:DataGrid ID="dgEmployees" runat="server" />
      	<p>The data will be refreshed 10 seconds from now: <%= DateTime.Now %></p>
      </form>
      </body>
      </html>
      thanks. -tj

      Comment

      • tjc0ol
        New Member
        • Nov 2007
        • 26

        #4
        Originally posted by Plater
        What version of asp.NET are you using? This looks like you are using VS2003 maybe?

        And are you sure that this page is
        A)Saved as an aspx page
        and
        B)Correctly deployed to the IIS server?

        Anyways I found it out my asp.NET version:
        VersionCheck results for my machine:

        Installed .NET Runtime(s)
        OK.
        Current version: The following runtimes are installed:
        1.1.4322.2407 Version 1.1 Post-SP1 with KB928366 Apr 2007
        2.0.50727.1433
        3.0.4506.30 Version 3.0 RTM (RTM 4506.30) Nov 2006

        ADO Database Runtime Version
        OK.
        Current version: 2.81.1132.0
        Determined from file: C:\Program Files\Common Files\System\ad o\msado15.dll

        Internet Explorer Version
        OK.
        Current version: 7.0.6000.16674
        Determined from file: C:\WINDOWS\syst em32\ieframe.dl l

        thanks. -tj

        Comment

        • tjc0ol
          New Member
          • Nov 2007
          • 26

          #5
          Originally posted by Plater
          What version of asp.NET are you using? This looks like you are using VS2003 maybe?

          And are you sure that this page is
          A)Saved as an aspx page
          and
          B)Correctly deployed to the IIS server?
          Hi Again,
          here's my ASP.NET version below:
          Version Information: Microsoft .NET Framework Version:2.0.507 27.1433; ASP.NET Version:2.0.507 27.1433

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            Are you sure that your DataGrid is being populated? If it isn't then the text in the <p> tags is the only other mark up on the page so would be the only thing that you'll see.

            If you put a breakpoint on the line
            Code:
            dgEmployees.DataSource = GetEmployees();
            and step through it, are you binding any data to the DataGrid?

            Dr B

            Comment

            • tjc0ol
              New Member
              • Nov 2007
              • 26

              #7
              Originally posted by DrBunchman
              Are you sure that your DataGrid is being populated? If it isn't then the text in the <p> tags is the only other mark up on the page so would be the only thing that you'll see.

              If you put a breakpoint on the line
              Code:
              dgEmployees.DataSource = GetEmployees();
              and step through it, are you binding any data to the DataGrid?

              Dr B
              Dr B,
              I think yes, as according to my code I placed the
              Code:
              dgEmployees.DataSource = GetEmployees();
              inside the
              Code:
              if(IsPostBack) {
              There is a binding of data to the DataGrid inside the
              Code:
              DataView GetEmployees() {
              	DataSet objDS = new DataSet();	
              	OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["DSN"]);
              	OleDbDataAdapter objDA;
              
              	objDV = (DataView)Cache["Employees"];
              	if (objDV == null) {
              		objDA = new OleDbDataAdapter("SELECT * FROM Employees", objConn);
              		objDA.Fill(objDS, "Employees");
              		objDV = objDS.Tables["Employees"].DefaultView;
              	dgEmployees.DataSource = objDS;
              	dgEmployees.DataBind();
              
              
              		Cache["Employees"] = objDV;
              	}
              	
              	return objDV;
              }
              This code came from my asp.net book and I think there's a new version of this code since the version of it is ASP.NET and I'm using .NET 2 now. I hope this will be resolved. thanks. -tj

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Do you have anything outside the:
                Code:
                if(isPostBack)
                {
                ...
                }
                Block?
                Because nothing inside that block will be executed the first time the page loads.
                You be wanting
                Code:
                if(!isPostBack)
                {
                ...
                }

                Comment

                • tjc0ol
                  New Member
                  • Nov 2007
                  • 26

                  #9
                  Originally posted by Plater
                  Do you have anything outside the:
                  Code:
                  if(isPostBack)
                  {
                  ...
                  }
                  Block?
                  Because nothing inside that block will be executed the first time the page loads.
                  You be wanting
                  Code:
                  if(!isPostBack)
                  {
                  ...
                  }
                  There is a code inside the block
                  Code:
                  void Page_Load() {
                      if (IsPostBack) {
                          dgEmployees.DataSource = GetEmployees();
                          dgEmployees.DataBind();
                      }
                  }
                  DataView GetEmployees() {
                  	DataSet objDS = new DataSet();	
                  	OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["DSN"]);
                  	OleDbDataAdapter objDA;
                  
                  	objDV = (DataView)Cache["Employees"];
                  	if (objDV == null) {
                  		objDA = new OleDbDataAdapter("SELECT * FROM Employees", objConn);
                  		objDA.Fill(objDS, "Employees");
                  		objDV = objDS.Tables["Employees"].DefaultView;
                  	dgEmployees.DataSource = objDS;
                  	dgEmployees.DataBind();
                  
                  
                  		Cache["Employees"] = objDV;
                  	}
                  	
                  	return objDV;
                  }
                  Just as in the first post. Thanks, -tj

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Ah ok, so you are never binding any data, so your page is blank.

                    Use this:
                    [code=c#]
                    void Page_Load() {
                    if (!IsPostBack) {
                    dgEmployees.Dat aSource = GetEmployees();
                    dgEmployees.Dat aBind();
                    }
                    }
                    [/code]
                    (Note: the ! before IsPostBack)

                    Comment

                    • tjc0ol
                      New Member
                      • Nov 2007
                      • 26

                      #11
                      Originally posted by Plater
                      Ah ok, so you are never binding any data, so your page is blank.

                      Use this:
                      [code=c#]
                      void Page_Load() {
                      if (!IsPostBack) {
                      dgEmployees.Dat aSource = GetEmployees();
                      dgEmployees.Dat aBind();
                      }
                      }
                      [/code]
                      (Note: the ! before IsPostBack)

                      thanks a lot this one solves the problem.

                      Comment

                      Working...