今天寫代碼,寫得前臺代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AlternateView.aspx.cs" Inherits="AlternateView" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>無標題頁</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="539px" Width="488px">
<asp:GridView ID="MyGridView" runat="server" DataKeyNames="CustomerID" DataSourceID="MySqlDS"
Width="488px" AutoGenerateColumns="False" BorderColor="White" OnRowCommand = "MyGridView_RowCommand">
<AlternatingRowStyle BackColor = "#C0C0FF" BorderStyle = "Double" />
<Columns>
<asp:BoundField DataField = "CustomerID" HeaderText = "CustomerID" InsertVisible = "False" ReadOnly = "True" SortExpression = "CustomerID"/>
<asp:TemplateField HeaderText = "CompanyName">
<ItemTemplate>
<% #DataBinder.Eval(Container.DataItem,"CompanyName")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField = "ContactName" HeaderText = "ContactName" InsertVisible = "False" ReadOnly = "True" SortExpression = "ContactName"/>
<asp:BoundField DataField = "City" HeaderText = "City" InsertVisible = "False" ReadOnly = "True" SortExpression = "City" />
<asp:BoundField DataField = "Country" HeaderText = "Country" InsertVisible = "False" ReadOnly = "True" SortExpression = "Country"/>
<asp:TemplateField HeaderText = "Operation">
<ItemTemplate>
<asp:Button ID = "ShowInformation" runat = "server" CommandName = "information" Text = "ShowInfo" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"CustomerID")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="MySqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [City], [Country] FROM [Customers]">
</asp:SqlDataSource>
<asp:Label ID="LabelMsg" runat="server" Width="144px"></asp:Label></asp:Panel>
</div>
</form>
</body>
</html>
後臺代碼如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class AlternateView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void MyGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToLower() == "information")
{
//顯示信息
LabelMsg.Text = "CustomerID = " + e.CommandArgument.ToString();
}
}
}
結果一直抱錯,錯誤信息如下:
編譯錯誤
說明: 在編譯向該請求提供服務所需資源的過程中出現錯誤。請檢查下列特定錯誤詳細信息並適當地修改源代碼。
編譯器錯誤信息: CS1024: 應輸入預處理器指令
源錯誤:
|
源文件: 行: 0
讓我抓狂了,找了好久沒有找到錯誤,暈了
|