M
mycwcgr
Unregistered / Unconfirmed
GUEST, unregistred user!
请问:为什么单点了按钮后,Output标签不显示内容
下面是我根据书上的例子改编的,其它一切正常,但当我单点Add to Cart按钮后,Output却没有显示内容,为什么?
<%@ Page language="c#"
Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="MyReport.WebForm1"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR"
Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE"
Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1"
method="post"
runat="server">
<asp:Repeater id="Repeater1"
runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td>Title</td>
<td>Title1</td>
<td>Title2</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem,"title" %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"price","{0:c}" %>
</td>
<td align="center">
<asp:Button Text="Add to Cart"
Runat="server"
CommandArgument='<%#DataBinder.Eval(Container.DataItem,"title" %>'/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Label ID="Output"
Runat="server"
/>
</form>
</body>
</HTML>
using 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.Data.SqlClient;
namespace MyReport
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Output;
protected System.Web.UI.WebControls.Repeater Repeater1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection connection=new SqlConnection(
"server=ccww;database=pubs;uid=cw;pwd="
);
connection.Open();
SqlCommand command=new SqlCommand("select * from titles where price!=0",connection);
SqlDataReader reader=command.ExecuteReader();
Repeater1.DataSource=reader;
Repeater1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Repeater1.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.Repeater1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
Output.Text=e.CommandArgument.ToString();
}
}
}
下面是我根据书上的例子改编的,其它一切正常,但当我单点Add to Cart按钮后,Output却没有显示内容,为什么?
<%@ Page language="c#"
Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="MyReport.WebForm1"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR"
Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE"
Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1"
method="post"
runat="server">
<asp:Repeater id="Repeater1"
runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td>Title</td>
<td>Title1</td>
<td>Title2</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem,"title" %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"price","{0:c}" %>
</td>
<td align="center">
<asp:Button Text="Add to Cart"
Runat="server"
CommandArgument='<%#DataBinder.Eval(Container.DataItem,"title" %>'/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Label ID="Output"
Runat="server"
/>
</form>
</body>
</HTML>
using 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.Data.SqlClient;
namespace MyReport
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Output;
protected System.Web.UI.WebControls.Repeater Repeater1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection connection=new SqlConnection(
"server=ccww;database=pubs;uid=cw;pwd="
);
connection.Open();
SqlCommand command=new SqlCommand("select * from titles where price!=0",connection);
SqlDataReader reader=command.ExecuteReader();
Repeater1.DataSource=reader;
Repeater1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Repeater1.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.Repeater1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
Output.Text=e.CommandArgument.ToString();
}
}
}