你这代码应该是在ASPX中吧?一个ASPX是一个类,你有见过在类中直接写这样代码的吗?所有的语句必须在方法中书写。

解决方案 »

  1.   

    哪为什么 <% ... %> 这样写就可以写到任何地方呢?
      

  2.   

    什么是code-behind什么是 in-line用程序具个例子?
      

  3.   

    in-line:我的程序是不用in-line的所以下的是从刚回的问题那边copy的
    <%
        DataTable dt=(DataTable)((ClassLibaray.ShopCar)Session["ShopCar"]).GetShopInfo();
        for(int i=0;i<dt.Rows.Count-1;i++)    
       {
        string strId="Login.aspx?id="+dt.Rows[i][6].ToString();
        string strName=dt.Rows[i][0].ToString();
        string strMyPrice=dt.Rows[i][3].ToString();
    %>
    <tr>
        <td style="WIDTH: 109px" align="right"><b>商品名称:</b></td>
        <td><a href='<%=strId%>'><%=strName%></a></td>
    <tr>
    <tr>
        <td style="WIDTH: 109px" align="right"><b>我的价格:</b></td>
        <td><%=strMyPrice%></td>
    <tr>
    <%
        }
    %>
    in-line:
    <FileList.aspx>
    <%@ Page language="c#" Codebehind="FileList.aspx.cs" AutoEventWireup="false" Inherits="UpFile.FileList" %>
    <%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <html>
    <head>
    <title>FileList</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    //-->
    </script>
    </head>
    <body ms_positioning="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:datagrid id="dg" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"
    height="56px" width="608px" autogeneratecolumns="False">
    <selecteditemstyle font-size="Larger" horizontalalign="Center"></selecteditemstyle>
    <edititemstyle font-size="Smaller" horizontalalign="Center"></edititemstyle>
    <alternatingitemstyle font-size="Smaller" horizontalalign="Center"></alternatingitemstyle>
    <itemstyle font-size="Smaller" horizontalalign="Center"></itemstyle>
    <headerstyle font-size="Smaller" horizontalalign="Center"></headerstyle>
    <columns>
    <asp:hyperlinkcolumn datanavigateurlfield="name" datanavigateurlformatstring="FileShow.aspx?file={0}"
    datatextfield="name" headertext="名称"></asp:hyperlinkcolumn>
    <asp:boundcolumn datafield="type" headertext="文件类型"></asp:boundcolumn>
    <asp:boundcolumn datafield="createtime" headertext="创建时间"></asp:boundcolumn>
    <asp:boundcolumn datafield="space" headertext="文件大小"></asp:boundcolumn>
    </columns>
    </asp:datagrid>&nbsp;&nbsp;
    </form>
    </body>
    </html>
    FileList.aspx.cssing System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;using System.IO;
    using Microsoft.Web.UI.WebControls;namespace UpFile
    {
    /// <summary>
    /// FileList 的摘要说明。
    /// </summary>
    public class FileList : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid dg;
    private void Page_Load(object sender, System.EventArgs e)
    {
    TreeOP top=new TreeOP();
    FileOP fop=new FileOP();
    DataView dvFile; if (!Page.IsPostBack)
    {
    dvFile=(top.GetFile(fop.Path)).DefaultView;
    dg.DataSource=dvFile;
    dg.DataBind();
    }
    else 
    {
    dvFile=(top.GetFile(Session["CurrPath"].ToString())).DefaultView;
    dg.DataSource=dvFile;
    dg.DataBind();
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion }
    }