为什么这样写就不对呢? 你这代码应该是在ASPX中吧?一个ASPX是一个类,你有见过在类中直接写这样代码的吗?所有的语句必须在方法中书写。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 哪为什么 <% ... %> 这样写就可以写到任何地方呢? 什么是code-behind什么是 in-line用程序具个例子? 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> </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 }} 征求C#的输入与输出方法 请教高手关于.Net程序调试出错的问题? c#.net开发界面(要求很高)另涉及少量数据库。请问看什么书。? 当页面有用户控件时,无法数据绑定了 新手问题……ACCESS操作,可以读取,但是不能修改 多个byte[]数组都存有各自的数据.我怎么把它保存起来(内存中)想用哪个的时候再从内存中取出来用. WINDOW XP与ASP。NET 1。1的问题 windows服务程序如何接受消息啊? Array类显式实现接口的问题 i++和++i有什么不同? c#导入excel数据时的怪问题:有一列只能导入数字,汉字和字母都认为是null!! c#连接数据库求助
<%
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>
</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 }
}